我正在尝试在React Native应用程序中设置redux,redux-thunk,redux-persist,我在做什么错了?
configStore.tsx
import {createStore} from 'redux';
import {rootReducer} from './reducers';
import {persistStore, persistReducer} from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import AsyncStorage from '@react-native-community/async-storage';
import {applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
const persistConfig = {
key: 'root',
storage: AsyncStorage,
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
export default () => {
let store = createStore(persistedReducer, applyMiddleware(thunk));
let persistor = persistStore(store);
return {store, persistor};
};
App.tsx
import React, {useState} from 'react';
import Drawer from './PreApp';
import {View, Text, Button, StyleSheet} from 'react-native';
import {Provider} from 'react-redux';
import store from './redux/configureStore';
import {PersistGate} from 'redux-persist/integration/react';
import persistor from './redux/configureStore';
const App = () => {
return (
<Provider store={store}>
<Drawer />
</Provider>
);
};
export default App;
答案 0 :(得分:3)
您要从configureStore
导出函数,首先需要调用它以获取store
和persistor
,然后可以将其传递给Provider
和{ {1}}。
PersistGate