54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { useDispatch, useSelector, TypedUseSelectorHook } from 'react-redux';
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
import {
|
|
createMigrate,
|
|
FLUSH,
|
|
PAUSE,
|
|
PERSIST,
|
|
persistReducer,
|
|
persistStore,
|
|
PURGE,
|
|
REGISTER,
|
|
REHYDRATE,
|
|
} from 'redux-persist';
|
|
import { ThunkAction } from 'redux-thunk';
|
|
import { Action, configureStore } from '@reduxjs/toolkit';
|
|
import { migrations, persistVersion } from './migration';
|
|
import rootReducer, { RootState } from './rootReducer';
|
|
import { injectStore } from '../services';
|
|
|
|
const persistConfig = {
|
|
key: 'root',
|
|
version: persistVersion,
|
|
storage: AsyncStorage,
|
|
blacklist: [],
|
|
migrate: createMigrate(migrations, { debug: __DEV__ }),
|
|
};
|
|
|
|
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
|
|
|
export const store = configureStore({
|
|
reducer: persistedReducer,
|
|
devTools: __DEV__,
|
|
middleware: getDefaultMiddleware =>
|
|
getDefaultMiddleware({
|
|
immutableCheck: false,
|
|
serializableCheck: {
|
|
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
|
|
},
|
|
}),
|
|
});
|
|
|
|
injectStore(store);
|
|
|
|
export const persistor = persistStore(store);
|
|
|
|
export type AppDispatch = typeof store.dispatch;
|
|
|
|
export const useAppDispatch = (): AppDispatch => useDispatch<AppDispatch>();
|
|
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
|
|
|
|
export type AppThunk = ThunkAction<void, RootState, unknown, Action<string>>;
|
|
|
|
export default store;
|