在 redux 存储更改后未重新渲染和更新 React 组件

时间:2021-05-20 17:30:05

标签: reactjs react-redux

1 个答案:

答案 0 :(得分:1)

沙盒链接问题已修复: 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

在react reducer中,对于数组使用 [...Array],对于对象使用{...object}