Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 8bb5689a

Přidáno uživatelem Michal Schwob před více než 1 rok

Added persistor storage to save app state
re #10821

Zobrazit rozdíly:

App.tsx
1 1
import 'react-native-gesture-handler'
2 2
import { NativeBaseProvider } from "native-base"
3 3
import { Provider } from "react-redux"
4
import store from "./src/stores/store"
4
import { store, Persistor } from "./src/stores/store"
5 5
import Navigation from "./src/pages/Navigation"
6 6
import { nativeBaseTheme } from "./src/theme/nativeBaseTheme"
7
import { PersistGate } from 'redux-persist/integration/react'
7 8

  
8 9
export default function App() {
9 10
    return (
10 11
        <Provider store={ store }>
11
            <NativeBaseProvider theme={ nativeBaseTheme }>
12
                <Navigation/>
13
            </NativeBaseProvider>
12
            <PersistGate persistor={Persistor}>
13
                <NativeBaseProvider theme={ nativeBaseTheme }>
14
                    <Navigation/>
15
                </NativeBaseProvider>
16
            </PersistGate>
14 17
        </Provider>
15 18
    )
16 19
}
package.json
15 15
    "@reduxjs/toolkit": "^1.9.3",
16 16
    "axios": "^1.3.4",
17 17
    "expo": "^49.0.13",
18
    "expo-splash-screen": "^0.10.3",
18
    "expo-splash-screen": "^0.20.5",
19 19
    "expo-status-bar": "~1.6.0",
20 20
    "native-base": "^3.4.28",
21 21
    "react": "18.2.0",
src/stores/store.ts
1 1
import { configureStore } from "@reduxjs/toolkit"
2
import { persistStore } from "redux-persist"
2 3
import userReducer from "./reducers/userSlice"
3 4
import itemReducer from "./reducers/itemSlice"
4 5
import searchFormReducer from "./reducers/searchFormSlice"
......
6 7
import homePageReducer from "./reducers/homePageSlice"
7 8
import noteViewReducer from "./reducers/notesSlice"
8 9

  
9
const store = configureStore({
10
export const store = configureStore({
10 11
    reducer: {
11 12
        user: userReducer,
12 13
        itemViewState: itemReducer,
......
17 18
    },
18 19
})
19 20

  
20
export default store
21
export const Persistor = persistStore(store)
22

  
23
export default { store, Persistor }
21 24
export type RootState = ReturnType<typeof store.getState>
22 25
export type AppStore = typeof store
23 26
export type AppDispatch = typeof store.dispatch

Také k dispozici: Unified diff