【问题标题】:redux-presist not updating local storage a browserredux-persist 不更新浏览器的本地存储
【发布时间】:2020-03-09 05:06:09
【问题描述】:

我正在为我的电子商务项目使用 redux-persist。

当我将我的应用更新到新版本时,我发现了一个新错误。

我将 initialState 从数组更改为对象。

我在 Chrome 中的应用程序(我在其上测试和运行我的应用程序的浏览器)崩溃了!!因为我的 initialState 仍然是数组(未更新)并且新方法没有返回任何东西。 (当然)。

但在 Mozilla 和其他我之前没有使用过的浏览器中,我的应用目前正在运行!

为什么!?

我的商店配置:

import { createStore, applyMiddleware } from 'redux'
import { persistStore } from 'redux-persist'
import logger from 'redux-logger'

import RootReducer from './RootReducer'

const middleware = [logger]

export const store = createStore(RootReducer, applyMiddleware(...middleware))

export const persistore = persistStore(store)

我的 rootReducer 配置:

import { combineReducers } from 'redux'
import { persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

import UserReducer from './User/UserReducer'
import ShoppingBagDropdownReducer from './ShoppingBagDropdown/ShoppingBagDropdownReducer'
import DirectoryReducer from './Directory/DirectoryReducer'
import ShopDataReducer from './ShopData/ShopDataReducer'

const persistConfig = {
    key: 'root',
    storage,
    whileList: ['shoppingBagDropdown']
}


const rootReducer = combineReducers({
    user: UserReducer,
    shoppingBagDropdown: ShoppingBagDropdownReducer,
    shopData: ShopDataReducer,
    directory: DirectoryReducer
})

export default persistReducer(persistConfig, rootReducer)

【问题讨论】:

    标签: reactjs local-storage redux-persist


    【解决方案1】:

    是的:)

    我找到了解决方案,那就是:清除本地存储:

    localStorage.clear();
    

    【讨论】:

      【解决方案2】:

      我看到你修复了它,但你也可以使用谷歌浏览器不使用代码。

      CTRL + SHIFT + I > Application > Local Storage 
      

      现在你只需要打开本地存储,右键点击清除。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-16
        • 1970-01-01
        • 2020-05-27
        • 1970-01-01
        相关资源
        最近更新 更多