DEV Community

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

Collapse
 
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?

Collapse
 
adamklein profile image
adam klein

Hi, glad to hear!
useReducer is a local state hook: reactjs.org/docs/hooks-reference.h...
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