What Is the State Reducer Pattern?

Why the State Reducer Pattern?

The state reducer pattern is the final and perhaps the most advanced pattern that we’ll be discussing in this course. Don’t let that scare you. I’ll take my time to explain how it really works while explaining why it matters too.

When we write custom hooks or components, they most likely have some way to keep track of the internal state. With the state reducer pattern, we give control to the user of our custom hook/component on how the state is updated internally.

State Updating In Regular Patterns

The technical term for this is called "inversion of control”. In layman terms, it means a system that allows the user to control how things work internally within your API.

Let’s look at how this works conceptually.

The typical flow for communicating updates to the user of your custom hook or component looks like this:

Get hands-on with 1400+ tech skills courses.