Implement The State Reducer Pattern Using The useReducer React Hook

Share this video with your friends

Send Tweet

One interesting pattern that you can implement by using the useReducer hook is the state reducer

This pattern - initially developed by Kent C. Dodds - is a way to implement an inversion of control mechanism, that is a way to allow the users of the component to tap into some internal logic of the same.

For this component, you can use this pattern to allow the user to control the initial state of the Wizard and add a custom action to the reducer pattern, thus giving even more flexibility when using the component.

In this lesson, you'll update the component API to implement this pattern allowing the user of the component to create its reducer function or even new actions or control the internal actions of the component.

Lucas Pereira Caixeta
~ 2 years ago

I guess this video became a bit complex with the combineReducer. Would love to read/see more about it in details, more examples :)

Zac Jones
~ 2 years ago

Hey @Lucas Pereira Caixeta, the examples in the new React docs on useReducer might help: https://beta.reactjs.org/apis/react/useReducer