How to fix Cannot perform a state update inside a useReducer without dispatching an action in React | DevErrors