连续更新两次store数据,第二次会拿到最初始的store比如initState ={ a:'', b:''};dispatch(setState(a,1))dispatch(setState(b,1))最终获得的state结果是{ a:'', b:1}如果换成setTimeout(()=>{ dispatch(setState(b,1))},0)能拿到正确值了但是不想代码中存在定时器reducer如下const initState = { a: '', b: ''}function test (state = initState, action) { switch (action.type) { case 'TEST_SET': return Object.assign({}, state, { [action.key]: action.value }); default: return state; }}有解决的办法吗
添加回答
举报
0/150
提交
取消
