-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
62 lines (57 loc) · 1.67 KB
/
App.tsx
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
import React,{ useState, useEffect } from 'react';
import { AsyncStorage, StyleSheet, Text, View } from 'react-native';
import AppNavigation from './navigation/AppNavigation';
import { Provider } from 'react-redux'
import Gate, { store } from './stores/store';
import NavigationService from './navigation/NavigationService';
import { ApolloClient } from '@apollo/client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider } from "@apollo/react-hooks"
import { persistCache } from 'apollo-cache-persist';
import { apolloLinks } from './services/graphql/ApolloLinks';
const styles = StyleSheet.create({
container: {
flex: 1
},
});
const App: React.FC = () => {
const [client, setClient] = useState(undefined);
useEffect(() => {
const cache = new InMemoryCache({});
const client = new ApolloClient({
//@ts-ignore
cache,
//@ts-ignore
link: apolloLinks
});
persistCache({
cache,
storage: AsyncStorage,
}).then(() => {
const initData = {};
client.writeData({
data: initData
});
client.onResetStore(async () => cache.writeData({ data: initData }));
setClient(client);
});
return () => {};
}, []);
if (client === undefined) return <View><Text>Loading</Text></View>;
return (
<View style={styles.container}>
<Gate>
<Provider store={store}>
<ApolloProvider client={client}>
<AppNavigation
ref={navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
/>
</ApolloProvider>
</Provider>
</Gate>
</View>
);
};
export default App;