I'm having a problem where updating my Context state with a reducer, sets the whole state as undefined... This is my code:
const [state, dispatch] = useReducer(AccountReducer, initialState);
The call to the Dispatch
dispatch({
type: SET_TOKEN,
payload: token
})
And the reducer
const AccountReducer = (state, action) => {
switch (action.type) {
case SET_TOKEN:
return {
...state,
token: action.payload
}
default:
break
}
};
After I make the dispatch the whole state is set to undefined.... Any ideas on why this is happening?