34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
|
|
import { configureStore, getDefaultMiddleware, combineReducers } from '@reduxjs/toolkit';
|
||
|
|
import { useSelector, TypedUseSelectorHook } from 'react-redux';
|
||
|
|
import AsyncStorage from '@react-native-community/async-storage';
|
||
|
|
import { persistStore, persistReducer } from 'redux-persist';
|
||
|
|
import logger from 'redux-logger';
|
||
|
|
|
||
|
|
const persistConfig = {
|
||
|
|
key: 'root',
|
||
|
|
storage: AsyncStorage,
|
||
|
|
};
|
||
|
|
|
||
|
|
import settings from './settings';
|
||
|
|
import music from './music';
|
||
|
|
|
||
|
|
const reducers = combineReducers({
|
||
|
|
settings,
|
||
|
|
music: music.reducer,
|
||
|
|
});
|
||
|
|
|
||
|
|
const persistedReducer = persistReducer(persistConfig, reducers);
|
||
|
|
|
||
|
|
const store = configureStore({
|
||
|
|
reducer: persistedReducer,
|
||
|
|
middleware: getDefaultMiddleware({ serializableCheck: false }).concat(logger, ),
|
||
|
|
});
|
||
|
|
|
||
|
|
export type AppState = ReturnType<typeof store.getState>;
|
||
|
|
export type AppDispatch = typeof store.dispatch;
|
||
|
|
export type AsyncThunkAPI = { state: AppState, dispatch: AppDispatch };
|
||
|
|
export const useTypedSelector: TypedUseSelectorHook<AppState> = useSelector;
|
||
|
|
|
||
|
|
export const persistedStore = persistStore(store);
|
||
|
|
|
||
|
|
export default store;
|