@@ -16,16 +16,18 @@ npm i @instantdb/react-native
16
16
npm i @react-native-async-storage/async-storage @react-native-community/netinfo react-native-get-random-values
17
17
```
18
18
19
- Now open up ` src/App.js ` in your favorite editor and replace the entirety of the file with the following code.
19
+ Now open up ` app/(tabs)/index.tsx ` in your favorite editor and replace the entirety of the file with the following code.
20
20
21
- ``` javascript {% showCopy=true %}
22
- import { init , tx } from ' @instantdb/react-native' ;
23
- import { View , Text , Button , StyleSheet } from ' react-native' ;
21
+ ``` typescript {% showCopy=true %}
22
+ import { init , tx } from " @instantdb/react-native" ;
23
+ import { View , Text , Button , StyleSheet } from " react-native" ;
24
24
25
25
// Instant app
26
26
const APP_ID = ' __APP_ID__' ;
27
27
28
- const db = init ({ appId: APP_ID });
28
+ type Schema = { colors: { color: string } };
29
+
30
+ const db = init <Schema >({ appId: APP_ID });
29
31
30
32
function App() {
31
33
const { isLoading, error, data } = db .useQuery ({ colors: {} });
@@ -44,21 +46,20 @@ function App() {
44
46
);
45
47
}
46
48
47
- return < Main data = {data} / > ;
49
+ return <Main colorEntity ={data . colors [ 0 ] } />;
48
50
}
49
51
50
- const selectId = ' 4d39508b-9ee2-48a3-b70d-8192d9c5a059' ;
52
+ const selectId = " 4d39508b-9ee2-48a3-b70d-8192d9c5a059" ;
51
53
52
- function Main ({ data }) {
53
- const { colors } = data;
54
- const { color } = colors[0 ] || { color: ' grey' };
54
+ function Main(props : { colorEntity? : { color: string } }) {
55
+ const { color } = props .colorEntity || { color: " white" };
55
56
56
57
return (
57
58
< View style = {[styles .container , { backgroundColor: color }]}>
58
- < View style= {styles .spaceY4 }>
59
+ <View style={[ styles .contentSection ] }>
59
60
<Text style={styles.header}>Hi! pick your favorite color</Text>
60
61
<View style={styles.spaceX4}>
61
- {[' green' , ' blue' , ' purple' ].map ((c ) => {
62
+ {[" green" , " blue" , " purple" ].map((c) => {
62
63
return (
63
64
<Button
64
65
title={c}
@@ -78,20 +79,26 @@ function Main({ data }) {
78
79
const styles = StyleSheet .create ({
79
80
container: {
80
81
flex: 1 ,
81
- justifyContent: ' center' ,
82
- alignItems: ' center' ,
82
+ justifyContent: " center" ,
83
+ alignItems: " center" ,
83
84
},
84
85
spaceY4: {
85
86
marginVertical: 16 ,
86
87
},
87
88
spaceX4: {
88
- flexDirection: ' row' ,
89
- justifyContent: ' space-between' ,
89
+ flexDirection: " row" ,
90
+ justifyContent: " space-between" ,
90
91
marginHorizontal: 16 ,
91
92
},
93
+ contentSection: {
94
+ backgroundColor: " white" ,
95
+ opacity: 0.8 ,
96
+ padding: 12 ,
97
+ borderRadius: 8 ,
98
+ },
92
99
header: {
93
100
fontSize: 24 ,
94
- fontWeight: ' bold' ,
101
+ fontWeight: " bold" ,
95
102
marginBottom: 16 ,
96
103
},
97
104
});
0 commit comments