File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-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,
21
+ defaultOptions : { watchQuery : { fetchPolicy : 'cache-and-network' } } ,
16
22
} )
17
23
18
24
export default function App ( ) {
25
+ const [ loadingCache , setLoadingCache ] = useState ( true )
26
+
27
+ useEffect ( ( ) => {
28
+ persistCache ( {
29
+ cache,
30
+ storage : AsyncStorage ,
31
+ } ) . then ( ( ) => setLoadingCache ( false ) )
32
+ } , [ ] )
33
+
34
+ if ( loadingCache ) {
35
+ return < AppLoading />
36
+ }
37
+
19
38
return (
20
39
< ApolloProvider client = { client } >
21
40
< NavigationContainer >
You can’t perform that action at this time.
0 commit comments