DEV Community

Discussion on: We don't know how React state hook works

alexkubica profile image
Alex Kubica

Thanks! I learned some new things here.
So if React has useReducer does it mean redux comes with React?
Also, I didn't understand what happens in basicStateReducer if the action isn't a function, how does the state get updated?

adamklein profile image
adam klein Author

Hi, glad to hear!
useReducer is a local state hook:
Redux is not part of React, it's a 3rd party library that manages global state
There are a lot of similarities because both of them update state using a reducer and dispatching actions.

If basicStateReducer receives a value that is not a function, it sets it as the new state.

So imagine a reducer that looks like this for plain values: (state, action) => action