state as object
See original GitHub issueHi, I tried to use an object in my state but it seems like there is an issue, I have to dispatch three times to get the updated state in my component.
This is the code:
const initialState = {
game: { pin: null }
};
export const reducer = (state = initialState, action) => {
console.log('state', state);
switch (action.type) {
case 'setNewGame':
return {
...state,
game: {
...state.game,
pin: action.gamePin
}
};
default:
return state;
}
};
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Updating Objects in State
State can hold any kind of JavaScript value, including objects. But you shouldn't change objects that you hold in the React state directly....
Read more >Updating an object with setState in React
To update the status of any todo object, run a map on the array and check for some unique value of each object,...
Read more >React State
The state object is where you store property values that belongs to the component. When the state object changes, the component re-renders. Creating...
Read more >State In React: An overview
State is a plain JavaScript object used by React to represent an information about the component's current situation.
Read more >Using React useState with an object
Learn how to use useState when working with objects by creating a temporary object and using object destructuring to create a new object....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks a lot for thunk example!
Just added
09_thunk
. Hope it helps.Let me close this issue.