File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 1
- import React from 'react'
1
+ import React , { useState , useEffect } from 'react'
2
2
import { StatusBar } from 'expo-status-bar'
3
3
import { NavigationContainer } from '@react-navigation/native'
4
4
import { createStackNavigator } from '@react-navigation/stack'
5
5
import { ApolloClient , InMemoryCache , ApolloProvider } from '@apollo/client'
6
+ import AsyncStorage from '@react-native-community/async-storage'
7
+ import { persistCache } from 'apollo3-cache-persist'
8
+ import { AppLoading } from 'expo'
6
9
7
10
import HomeScreen from './src/HomeScreen'
8
11
import ChapterScreen from './src/ChapterScreen'
9
12
import { screenOptions } from './src/styles'
10
13
11
14
const Stack = createStackNavigator ( )
12
15
16
+ const cache = new InMemoryCache ( )
17
+
13
18
const client = new ApolloClient ( {
14
19
uri : 'https://api.graphql.guide/graphql' ,
15
- cache : new InMemoryCache ( ) ,
20
+ cache,
16
21
} )
17
22
18
23
export default function App ( ) {
24
+ const [ loadingCache , setLoadingCache ] = useState ( true )
25
+
26
+ useEffect ( ( ) => {
27
+ persistCache ( {
28
+ cache,
29
+ storage : AsyncStorage ,
30
+ } ) . then ( ( ) => setLoadingCache ( false ) )
31
+ } , [ ] )
32
+
33
+ if ( loadingCache ) {
34
+ return < AppLoading />
35
+ }
36
+
19
37
return (
20
38
< ApolloProvider client = { client } >
21
39
< NavigationContainer >
You can’t perform that action at this time.
0 commit comments