-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.ts
46 lines (39 loc) · 1.51 KB
/
store.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { combineReducers, configureStore } from "@reduxjs/toolkit";
import { useDispatch } from "react-redux";
import petsReducer from "./slices/petsSlice";
import dogDataReducer from "./slices/dogFactsSlice";
import generalInfoReducer from "./slices/generalInfoSlice";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { persistStore, persistReducer, FLUSH,
REHYDRATE,
PAUSE,
PERSIST,
PURGE,
REGISTER, } from "redux-persist"
// the redux-persist library is used here as an efficient way of combining the state data and the data persisted to the async-storge
// this is a BIG improvement from the first draft app which manually pulled from and saved to async-storage throughout the app usage
// persist config
const persistConfig = {
key: "root",
storage: AsyncStorage
};
const rootReducer = combineReducers({
pets: petsReducer,
petInfo: generalInfoReducer,
dogFacts: dogDataReducer,
});
// wrapping root reducer with persistReducer
const persistedReducer = persistReducer(persistConfig, rootReducer);
export const store = configureStore({
reducer: persistedReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
}),
});
export const persistor = persistStore(store);
export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch;
export const useAppDispatch: () => AppDispatch = useDispatch;