useContext - Theme Provider


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

Saved by @thecowsays #react #usecontext #react.js

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 }}>

credit goes to Byron Holmes x Mimo Bootcamp