我有一个购物车网站和用户购物车存储在localStorage
。
现在,当我的页面刷新时,我想用我的localStorage初始化我的商店,但是我收到了这个错误:
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