forked from apollographql/apollo-cache-persist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
60 lines (51 loc) · 1.51 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/react-native-community/react-native-template-typescript
*
* @format
*/
import React, { useCallback, useState } from 'react';
import {
Button,
DevSettings,
SafeAreaView,
StyleSheet,
Text,
View,
} from 'react-native';
import { ApolloProvider } from '@apollo/client';
import { Launches } from './src/Launches';
import { Ships } from './src/Ships';
import { useApolloClient } from './src/hooks';
const App = () => {
const [display, setDisplay] = useState<number>(0);
const { client, clearCache } = useApolloClient();
const reload = useCallback(() => {
DevSettings.reload();
}, []);
if (!client) {
return <Text style={styles.heading}>Initializing app...</Text>;
}
return (
<ApolloProvider client={client}>
<SafeAreaView style={{ ...StyleSheet.absoluteFillObject }}>
<View style={styles.content}>
{display % 2 === 0 ? <Launches /> : <Ships />}
</View>
<View style={styles.controls}>
<Button title={`Show ${display % 2 ? 'Launches' : 'Ships'}`} onPress={() => setDisplay(display + 1)} />
<Button title={'Clear cache'} onPress={clearCache} />
<Button title={'Reload app (requires dev mode)'} onPress={reload} />
</View>
</SafeAreaView>
</ApolloProvider>
);
};
const styles = StyleSheet.create({
content: { flex: 1 },
controls: { flex: 0 },
});
export default App;