-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
67 lines (57 loc) · 1.86 KB
/
Copy pathApp.js
File metadata and controls
67 lines (57 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React, { useState, useEffect } from 'react'
import { StatusBar } from "expo-status-bar";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { ApolloClient, InMemoryCache, ApolloProvider } from "@apollo/client";
import AsyncStorage from '@react-native-community/async-storage'
import { persistCache } from 'apollo3-cache-persist'
import Loading from "./src/Loading";
import HomeScreen from "./src/HomeScreen";
import ChapterScreen from './src/ChapterScreen'
import { screenOptions } from "./src/styles";
const Stack = createStackNavigator();
const cache = new InMemoryCache()
const client = new ApolloClient({
uri: "https://api.graphql.guide/graphql",
cache,
defaultOptions: { watchQuery: { fetchPolicy: 'cache-and-network' } },
});
export default function App() {
const [loadingCache, setLoadingCache] = useState(true)
useEffect(() => {
persistCache({
cache,
storage: AsyncStorage,
}).then(() => setLoadingCache(false))
}, [])
if (loadingCache) {
return <Loading />
}
return (
<ApolloProvider client={client}>
<NavigationContainer>
<Stack.Navigator initialRouteName="Home" screenOptions={screenOptions}>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ title: "📖 The GraphQL Guide" }}
/>
<Stack.Screen
name="Chapter"
component={ChapterScreen}
options={({
route: {
params: {
chapter: { number, title },
},
},
}) => ({
title: number ? `Chapter ${number}: ${title}` : title,
})}
/>
</Stack.Navigator>
<StatusBar style="light" />
</NavigationContainer>
</ApolloProvider>
);
}