我正在使用 React-native 和 Redux,但是我的应用程序非常小而且简单,所以我认为 redux-react 不需要开销,所以我没有使用它。我只是在需要时导入商店,因为无论如何它都是单身人士。但是现在使用 redux-persist 我"TypeError: undefined is not an object (evaluating 'this.props.persistor.subscribe')"
从 App.js 收到一个错误,所以我想这可能是因为我没有使用 store Provider。这是真的吗?
configureStore.js
import { createStore } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import rootReducer from './reducers/reducer';
const persistConfig = {
key: 'root',
storage: storage,
}
const persistedReducer = persistReducer(persistConfig, rootReducer);
let store = createStore(persistedReducer);
let persistor = persistStore(store);
export default { store, persistor };
应用程序.js
import React from 'react';
import RootContainer from './src/components/containers/root-container';
import { PersistGate } from 'redux-persist/lib/integration/react';
import { persistor } from './src/configureStore';
export default class App extends React.Component {
render() {
return (
<PersistGate loading={null} persistor={persistor}>
<RootContainer />
</PersistGate>
);
}
}
感谢帮助