Snippets Collections
import { createContext, useState } from "react";

export const ThemeContext = createContext();

// pass the prop children; a provider is needed here
export default function ThemeContextProvider({ children }) {
  // boolean for default setting
  const [darkMode, setDarkMode] = useState(true);
  return (
    // allows darkMode and setDarkMode to be used
    <ThemeContext.Provider value={{ darkMode, setDarkMode }}>

Wed Aug 30 2023 23:57:12 GMT+0000 (Coordinated Universal Time)

#react #usecontext #react.js

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension