user-avatar

Kyle J. Roux

jstacoder

Developer Program Member

a python/javascript/php/linux guru ready to take on the world...

CasePeer
orange, CA, USA
https://jstacoder.github.io

Hi
Home

Jstacoders Profile
06 24 2019 dark mode hookDark Mode:2019 06 09 graphql and gatsby2019 06 13 graphql schema definition 101About linkAdd Blog
Blog
Commit blockCommit block list
Components
General
GridGrid2Header linksHeader logoHomeIndexMy ProfileSidebarTable notesselect-dropbox-root-foldersodebrrr

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: '',
},
}
Home