Commit 5a29b0a 1 parent 74463aa commit 5a29b0a Copy full SHA for 5a29b0a
File tree 2 files changed +28
-8
lines changed
2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,13 @@ import ReactDOM from 'react-dom/client';
3
3
import App from './components/App' ;
4
4
import './index.css' ;
5
5
import { Provider as ReduxProvider } from 'react-redux' ;
6
- import persistor from './redux/store.js' ;
6
+ import { PersistGate } from 'redux-persist/integration/react' ;
7
+ import { persistor , store } from './redux/store' ;
7
8
8
9
ReactDOM . createRoot ( document . getElementById ( 'root' ) ) . render (
9
- < ReduxProvider store = { persistor } >
10
- < App />
10
+ < ReduxProvider store = { store } >
11
+ < PersistGate loading = { null } persistor = { persistor } >
12
+ < App />
13
+ </ PersistGate >
11
14
</ ReduxProvider >
12
15
) ;
Original file line number Diff line number Diff line change 1
- import { configureStore } from '@reduxjs/toolkit' ;
1
+ import { combineReducers , configureStore } from '@reduxjs/toolkit' ;
2
2
import { contactsReducer } from './slices/contactsSlice' ;
3
3
import { filterReducer } from './slices/filterSlice' ;
4
4
5
+ import { persistReducer , persistStore } from 'redux-persist' ;
6
+ import storage from 'redux-persist/lib/storage' ;
7
+
5
8
/**
6
9
* In store, pentru fiecare "particica" din state-ul aplicatiei, o sa asignam un reducer care se va ocupa exclusiv de logica pentru acea "particica".
7
10
*
@@ -12,11 +15,25 @@ import { filterReducer } from './slices/filterSlice';
12
15
* }
13
16
*/
14
17
15
- const store = configureStore ( {
16
- reducer : {
18
+ const persistConfig = {
19
+ key : 'root' ,
20
+ storage,
21
+ } ;
22
+
23
+ const persistedReducer = persistReducer (
24
+ persistConfig ,
25
+ combineReducers ( {
17
26
contacts : contactsReducer ,
18
27
filter : filterReducer ,
19
- } ,
28
+ } )
29
+ ) ;
30
+
31
+ export const store = configureStore ( {
32
+ reducer : persistedReducer ,
33
+ middleware : getDefaultMiddleware =>
34
+ getDefaultMiddleware ( {
35
+ serializableCheck : false ,
36
+ } ) ,
20
37
} ) ;
21
38
22
- export default store ;
39
+ export const persistor = persistStore ( store ) ;
You can’t perform that action at this time.
0 commit comments