我想将特定reducer的当前状态保存到会话存储中,而不必在每个操作中明确调用它。Redux reducer - on state change
const { handleActions } = require("redux-actions");
// How do i make this logic run on any state change without adding it to every action?
const onStateChange = (state) => sessionStorage.save(keys.myReducer, state);
const myReducer = handleActions
({
[Actions.action1]: (state, action) => (
update(state, {
prop1: {$set: action.payload},
})
),
[Actions.action2]: (state, action) => (
update(state, {
prop2: {$set: action.payload},
})
)
},
//****************INITIAL STATE***********************
{
prop1: [],
prop2: []
}
);
有没有办法赶上特定减速的状态变化的事件吗?
我知道store.subscribe
,但是这对整个商店,我说的是听一个特定的减速变化
感谢
您是否尝试过像[redux-localstorage](https://github.com/elgerlambert/redux-localstorage)或[redux-persist](https://github.com/rt2zz/redux-persist)这样的库?或者你是否正在处理这些库无法解决的利基用例? – excalliburbd
@excalliburbd - 坚持状态不是唯一的逻辑我想运行状态改变,所以不幸的是这并不能解决问题 – Daniel