I have a shopping cart website and cart of user stored in localStorage
.
now, I want to initial my store with my localStorage when my page will refresh but I get this error:
localStorage is not defined
cart.reducer.js:
import { cartConstants } from '../constants';
import { cartHelper } from '../helpers'
const initialState = []
function cart(state = initialState, action) {
if(state.length == 0){
state = cartHelper.getCart(); // error line
}
switch (action.type) {
case cartConstants.CART:
return action.cart
default:
return state
}
}
export default cart