06 24 2019 dark mode hookDark Mode:2019 06 09 graphql and gatsby2019 06 13 graphql schema definition 101About linkAdd BlogCommit blockCommit block listGridGrid2Header linksHeader logoHomeIndexMy ProfileSidebarTable notesselect-dropbox-root-foldersodebrrr
Components
Flex
General
Layouts
Projects
blogs
Dark Mode:
The react hooks way
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: '',},}