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?
I'm a web developer and consultant, web GDE, and author of open source libraries. I co-founded 500Tech, a company that specializes in frontend technologies. I love coding, and love speaking about code
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
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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?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