update the store data twice in a row, and the second time you will get the original store
such as
initState ={
a:"",
b:""
};
dispatch(setState(a,1))
dispatch(setState(b,1))
the final state result is
{
a:"",
b:1
}
if you replace it with
setTimeout(()=>{
dispatch(setState(b,1))
},0)
can get the correct value
but don"t want a timer in the code
reducer is as follows
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;
}
}
is there a solution