In-store I have an array called visited:[]
. In a function called changeInfo
first I need to clear the array and then add an item to the array.
const changeInfo = (value) => {
dispatch(clearVisited());
console.log("before visited", visited);
dispatch(addToVisited(value));
console.log("after visited", visited);
};
Some can argue that I can have an action type clearAndInsert
and reducer like this
case CLEAR_AND_INSERT:
return {
visited: [action.payload],
};
But this is not wanted I want. I want to dispatch clearVisited and wait until after it clears the array and after that dispatch addToVisited.Want I am getting for the console logs for changeInfo
is strange.
HOW CAN I CALL TWO ACTIONS SYNCHRONOUSLY IN REACT?