Dinesh Sonachalam
Dinesh Sonachalam

Reputation: 1369

React component was not re-rendered and updated after redux store change

Sandbox Link to reproduce this issue: https://codesandbox.io/s/redux-component-store-issue-kegqo

enter image description here

Upvotes: 1

Views: 21

Answers (1)

Dinesh Sonachalam
Dinesh Sonachalam

Reputation: 1369

Sandbox Link issue fixed: https://codesandbox.io/s/fix-redux-component-store-issue-j7oxb?file=/src/redux/reducers/userReducer.js

const userReducer = (state=initialState, actions) => {
    switch(actions.type) {
        case UPDATE_USERS:
            return {...state, users: [...actions.payload.users]}
        default:
            return {...state}
    }
}

enter image description here

In the react reducer, for array use [...Array], for the object use {...object}

Upvotes: 1

Related Questions