a python/javascript/php/linux guru ready to take on the world...
1 min read
Here I will show how to use reacts new useContext
and useReducer
hooks by adding a dark mode toggle to a react app
To start out we will need three things:
A light colored theme object
A dark colored theme object
A way to provide the theme to your components
For the themes i prefer to combine them into a single themes
object
import { dark } from './themes/dark'import { light } from './themes/light'export const themes = {dark,light,}
And for the themes i like to define general names for colors to use
export const light = {colors: {lightText: '',darkText: '',lightBackground: '',darkBackground: '',primary: '',secondary: '',},}