-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alder Whiteford
authored and
Alder Whiteford
committed
Jun 11, 2024
1 parent
290553f
commit 4d98763
Showing
7 changed files
with
77 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
import { Provider } from "react-redux"; | ||
import { PersistGate } from "redux-persist/integration/react"; | ||
import { persistor, store } from "@/src/store/store"; | ||
import { Provider } from 'react-redux'; | ||
|
||
import { PersistGate } from 'redux-persist/integration/react'; | ||
|
||
import { persistor, store } from '@/src/store/store'; | ||
|
||
type StoreProviderProps = { | ||
children: React.ReactNode; | ||
} | ||
children: React.ReactNode; | ||
}; | ||
|
||
/** | ||
* The Redux store provider component. This makes the store accessible globally across the repository | ||
*/ | ||
export default function StoreProvider({ children }: StoreProviderProps) { | ||
return ( | ||
<Provider store={store}> | ||
<PersistGate loading={null} persistor={persistor}> | ||
{children} | ||
</PersistGate> | ||
</Provider> | ||
) | ||
return ( | ||
<Provider store={store}> | ||
<PersistGate loading={null} persistor={persistor}> | ||
{children} | ||
</PersistGate> | ||
</Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,72 @@ | ||
import { baseApi } from "@generatesac/lib"; | ||
import { combineReducers, configureStore } from "@reduxjs/toolkit"; | ||
import { useDispatch, useSelector, useStore } from "react-redux"; | ||
import userReducer from "@/src/store/slices/userSlice"; | ||
import persistReducer from "redux-persist/es/persistReducer"; | ||
import { useDispatch, useSelector, useStore } from 'react-redux'; | ||
|
||
import { baseApi } from '@generatesac/lib'; | ||
import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
import { thunk } from "redux-thunk"; | ||
import { combineReducers, configureStore } from '@reduxjs/toolkit'; | ||
import { | ||
FLUSH, | ||
PAUSE, | ||
PERSIST, | ||
PURGE, | ||
REGISTER, | ||
REHYDRATE, | ||
persistStore, | ||
} from "redux-persist"; | ||
import autoMergeLevel2 from "redux-persist/es/stateReconciler/autoMergeLevel2"; | ||
FLUSH, | ||
PAUSE, | ||
PERSIST, | ||
PURGE, | ||
REGISTER, | ||
REHYDRATE, | ||
persistStore | ||
} from 'redux-persist'; | ||
import persistReducer from 'redux-persist/es/persistReducer'; | ||
import autoMergeLevel2 from 'redux-persist/es/stateReconciler/autoMergeLevel2'; | ||
import { thunk } from 'redux-thunk'; | ||
|
||
import userReducer from '@/src/store/slices/userSlice'; | ||
|
||
const rootReducer = combineReducers({ | ||
user: userReducer, | ||
[baseApi.reducerPath]: baseApi.reducer, | ||
user: userReducer, | ||
[baseApi.reducerPath]: baseApi.reducer | ||
}); | ||
|
||
type RootReducer = ReturnType<typeof rootReducer>; | ||
|
||
const persistanceConfig = { | ||
key: "root", | ||
storage: AsyncStorage, | ||
stateReconciler: autoMergeLevel2, | ||
blacklist: [baseApi.reducerPath], | ||
whitelist: ["user"], | ||
key: 'root', | ||
storage: AsyncStorage, | ||
stateReconciler: autoMergeLevel2, | ||
blacklist: [baseApi.reducerPath], | ||
whitelist: ['user'] | ||
}; | ||
|
||
const persistedReducer = persistReducer<RootReducer>( | ||
persistanceConfig, | ||
rootReducer, | ||
persistanceConfig, | ||
rootReducer | ||
); | ||
|
||
export const store = | ||
configureStore({ | ||
export const store = configureStore({ | ||
middleware: (getDefaultMiddleware) => | ||
getDefaultMiddleware({ | ||
serializableCheck: { | ||
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER], | ||
} | ||
}) | ||
.concat(baseApi.middleware) | ||
.concat(thunk), | ||
|
||
getDefaultMiddleware({ | ||
serializableCheck: { | ||
ignoredActions: [ | ||
FLUSH, | ||
REHYDRATE, | ||
PAUSE, | ||
PERSIST, | ||
PURGE, | ||
REGISTER | ||
] | ||
} | ||
}) | ||
.concat(baseApi.middleware) | ||
.concat(thunk), | ||
|
||
reducer: persistedReducer, | ||
devTools: process.env.NODE_ENV !== "production", | ||
}); | ||
devTools: process.env.NODE_ENV !== 'production' | ||
}); | ||
|
||
export const persistor = persistStore(store); | ||
|
||
// Redux types: | ||
export type AppStore = typeof store | ||
export type RootState = ReturnType<AppStore['getState']> | ||
export type AppDispatch = AppStore['dispatch'] | ||
export type AppStore = typeof store; | ||
export type RootState = ReturnType<AppStore['getState']>; | ||
export type AppDispatch = AppStore['dispatch']; | ||
|
||
// Typed Redux interactive methods: | ||
export const useAppDispatch = useDispatch.withTypes<AppDispatch>() | ||
export const useAppSelector = useSelector.withTypes<RootState>() | ||
export const useAppStore = useStore.withTypes<AppStore>() | ||
export const useAppDispatch = useDispatch.withTypes<AppDispatch>(); | ||
export const useAppSelector = useSelector.withTypes<RootState>(); | ||
export const useAppStore = useStore.withTypes<AppStore>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters