修改Redux存储后刷新组件

h7wcgrx3  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(89)

在创建存储后,当我修改JASON文件中的数据时,刷新到达连接函数,但组件没有重建。
我想这是由不变性引起的我有发现

存储

function songReduceur(state = initialState, action) {
    switch (action.type) {
        case CONSTANTS.DELETE_CHORD:
            let DELETE_C_newChordOrder = state.mesures[action.mesure].chordOrder
            DELETE_C_newChordOrder.splice(action.index, 1)

            return {
                ...state,
                mesures:{
                    ...state.mesures,
                    [action.mesure]: {
                        ...state.mesures[action.mesure],
                        chordOrder: DELETE_C_newChordOrder
            }}}
        default:
            return state
    }
}

export default songReduceur

组件

此处状态为update,但不是组件MesureArea本身的状态

const mapStateToProps = (state, ownProps) => {
    const id = ownProps.id
    return {
        chiffrage: state.song.mesures[id].chiffrage,
        chordOrder: state.song.mesures[id].chordOrder,
        chordHistoric: state.song.chordHistoric
    }
}

export default connect(mapStateToProps)(MesureArea)
x4shl7ld

x4shl7ld1#

解决方案

错误还是在于不变性x)类似于

chordOrder: [...DELETE_C_newChordOrder]

相关问题