Reducer-添加新元素

问题描述 投票:0回答:2

我有这家商店:

const initialActors = {
    list: 'Actor\'s lists',
    actors: [
        {
            name: 'Angelina Jole',
            involved: true
        },
        {
            name: 'Bratt Pitt',
            involved: false
        },
    ]
}

我有一个简化器可以在我的商店中添加一个新演员:

const actors = (state = initialActors, action) => {
    switch(action.type){
        case 'ADD_NEW':
            return {
                ...state.list,
                actors: [
                    ...state.actors,
                    action.name,
                    action.involved
                ]
            }
        default:
            return state
    }
}

我也有动作创作者,但这并不重要。我调度并显示我的状态:

store.dispatch(addNew({name: "Hello", involved: true}) ); // I have this action creator
console.log(store.getState()

console.log显示非常困难的对象,其字母类似于:{0: "A", 1: "c"}。怎么了?

javascript reactjs redux store
2个回答
0
投票
喜欢这个:

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.