October 2019
Intermediate to advanced
426 pages
11h 49m
English
After defining the actions and the reducer function, we are going to define the Reducer Hook, and pass its state and the dispatch function to the components that need it.
Let's start implementing the Reducer Hook:
import React, { useState, useReducer } from 'react'
const [ user, setUser ] = useState('')
Replace the preceding State Hook with a Reducer Hook—the initial state is an empty string, as we had it before:
const [ user, dispatchUser ] = useReducer(userReducer, '')
Read now
Unlock full access