Consider the following reducer:
const initialBaseTestState = {
oldValue: "String",
something: "String two",
};
const baseTest = produce((state = initialBaseTestState, action) => {
const { type, data } = action;
switch (type) {
case SET_VALUE: {
state.newValue = "test";
sendUpdatedState(original(state)); // Send updated state
return state;
}
Code of function sendUpdatedState:
export const updateMonthlyTotalPrice = updatedState => {
const dispatch = useDispatch();
console.log(updatedState);
// Getting: {oldValue: "String", something: "String two"}
// Requiring: {oldValue: "String", something: "String two", newValue: "test"}
const string = updatedState.newValue + "s";
dispatch(setSomeValueAction(string));
};
I know when the original
is called with 'old' state, so why I am getting the initialBaseTestState
. Is it some approach to get already updated state
after the state.newValue
is updated in produce
.
NOTE: I would like to keep using the Immer