After learning how to implement themes in a small example, we are now going to implement themes in our blog app, using React context and Hooks.
Implementing themes
Defining the context
First, we have to define the context. Instead of defining it in the src/App.js file, in our blog app, we are going to create a separate file for the context. Having a separate file for contexts makes it easier to maintain them later on. Furthermore, we always know where to import the contexts from, because it is clear from the filename.
Let's start defining a theme context:
- Create a new src/contexts.js file.
- Then, we import React:
import React from 'react'
- Next, we define the ThemeContext. As before in our small example, we...