Port to Redux and add settings

This commit is contained in:
Lei Nelissen
2020-06-17 14:58:04 +02:00
parent cffc7567c1
commit 2369ef68ae
22 changed files with 730 additions and 158 deletions

34
src/store/index.ts Normal file
View File

@@ -0,0 +1,34 @@
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;