Implementing the State Reducer Pattern
Let’s integrate the state reducer pattern into the scenario we studied earlier
We'll cover the following
Our solution to the hacker’s feature request is to implement the state reducer pattern.
When the reader clicks the Header
element, we’ll communicate the changes we propose to be made internally to the hacker, i.e., we’ll let the hacker know we want to update the expanded state internally.
The hacker will then check their own application state. If the reader has already viewed the secret resource, the hacker will communicate to our custom hook NOT to allow a state update.
There it is. The power of the state reducer pattern, giving control of the internal state updates to the user.
Implementation
Now, let’s write the technical implementation.
First, we’ll expect a second argument from the hacker, their own reducer.
Get hands-on with 1400+ tech skills courses.