我有这个initialState
const initialState = Immutable.fromJS({
list: [],
entities: {},
something: {
otherOne: false,
otherTwo: false,
},
});
我想用这样的函数更新对象something
:
[UPDATE_SOMETHING]: (state, { key }) => { // <== key is the name of the nested props
return state.merge({
filterBy: {[key]: !state.get('key')},
});
),
但它不起作用......我如何动态更新状态?
答案 0 :(得分:2)
[UPDATE_SOMETHING]: (state, {key}) => {
const something = state.get('something').withMutations(s => {
s.set(key, !s.get(key));
});
return state.set('something', something);
),
这样的事情会有所帮助吗?