For example...
export const user = (state = {
id: localStorage.getItem('id'),
name: localStorage.getItem('name'),
loggedInAt: null
}, action) => {
case types.LOGIN:
localStorage.setItem('name', action.payload.user.name);
localStorage.setItem('id', action.payload.user.id);
return { ...state, ...action.payload.user }
default:
return { ...state, loggedInAt: Date.now() }
}
That's a scaled down version of what I'm doing, default returns the state from localStorage as expected. However the state of my application is actually blank once I refresh the page.
should you?
? depending on your application needs. – Idonah