You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
I think the problem is on useDispatch, when it's calling a reducer it pass a different action object. I even tried to copy and pest your count example on README, I got the same result.
Thank you. The documentation is wrong there. It was correct in 1.x, but should have been updated since! As of 2.x, the second parameter is dispatch, an object that contains and dispatches all of your reducers.
In your example, however, myReducer should be returning { names: ... } instead of ..., because it is returning a partial global state. Think of it like this.setState in a class Component, if you are familiar with those.
// 2.0.xconstmyReducer=(state,dispatch,action="hello")=>{// added dispatchswitch(action.type){case"PUSH":
return{names: [...state.names,action.text]};// added names propertycase"PULL":
return{names: state.names.filter(val=>val!=action.text)};// added names propertydefault:
returnnull;// no state change}}// ...constdispatch=useDispatch(myReducer);
Issue #82 is not implemented yet, but it will remove this redundancy. I've just released 2.1.1, which allows you to do useDispatch(myReducer, 'names'), which behaves similar to React's native useReducer.
Thanks for clarification, I like the 2nd approach, it's easy to follow, and it doesn't change the structure of reducers, unlike the 1st approach. I've upgraded to v2.1.2 and tried it, works really well.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I think the problem is on useDispatch, when it's calling a reducer it pass a different action object. I even tried to copy and pest your count example on README, I got the same result.
Here is how to reproduce it
The text was updated successfully, but these errors were encountered: