I'm trying to setup redux, redux-thunk, redux-persist in a React Native app, What am I doing wrong?
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;
You are exporting a function from the
configureStore
you will first need to call it to get thestore
&persistor
which you can later passed to theProvider
&PersistGate
.