【问题标题】:redux-persist failed to create sync storage. failing back to noop storage. What does this mean?redux-persist 无法创建同步存储。失败回到 noop 存储。这是什么意思?
【发布时间】:2021-08-15 19:13:44
【问题描述】:

我是一名初学者,正在创建我的第一个 react-native 移动应用。我一直坚持这个错误,我不明白我在这里做错了什么。 我将提供我使用 redux-persist 的所有代码以供参考。

首先是我的 store.js 文件,我在其中为我的 Redux 实现创建一个商店。这是一个小文件,所以我将提供所有文件。

import {createStore, applyMiddleware} from 'redux'
import thunk from 'redux-thunk'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

//the reducer i implemented
import reducer from './reducer'

const persistConfig = {
  key: 'root',
  storage,
}

const persistedReducer = persistReducer(persistConfig, reducer)

export const store = createStore(persistedReducer, applyMiddleware(thunk))
export const persistor = persistStore(store)

现在是我的 App.js 文件:

这是我为了商店而导入的两个库:

import {Provider} from 'react-redux'
import { PersistGate } from 'redux-persist/integration/react'

import {store, persistor} from './redux/store'

我在其中呈现主导航器的 App 类:

export default class App extends React.Component {
  state = {
    //contacts,
  }
render() {
    return (
      <Provider store={store}>
        <PersistGate loading={null} persistor={persistor}>
          <AppNavigator />
        </PersistGate>
      </Provider>
    )
  }
}

如何调试我的代码?

【问题讨论】:

    标签: reactjs react-native redux react-redux redux-persist


    【解决方案1】:

    好的,您的 App.js 没问题。就像 store.js 文件中的导入一样。但是我对你导入的“存储”没有经验,我用过AsyncStorage我建议你看看这个存储。

    现在调试我推荐你使用Flipper工具,它有一个用于设备的Redux部分,虽然安装有点乏味,但我相信它会对你有所帮助。您可以指导自己在您的应用程序中实现它here

    【讨论】:

      猜你喜欢
      • 2020-12-13
      • 2020-01-06
      • 1970-01-01
      • 2021-06-24
      • 2022-01-25
      • 1970-01-01
      • 2011-11-12
      • 2021-12-26
      相关资源
      最近更新 更多