Skip to content

Commit 4447d54

Browse files
authored
[docs] update rn starter (#628)
1 parent 1903d13 commit 4447d54

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

client/www/pages/docs/start-rn.md

+24-17
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ npm i @instantdb/react-native
1616
npm i @react-native-async-storage/async-storage @react-native-community/netinfo react-native-get-random-values
1717
```
1818

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.
2020

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";
2424

2525
// Instant app
2626
const APP_ID = '__APP_ID__';
2727

28-
const db = init({ appId: APP_ID });
28+
type Schema = { colors: { color: string } };
29+
30+
const db = init<Schema>({ appId: APP_ID });
2931

3032
function App() {
3133
const { isLoading, error, data } = db.useQuery({ colors: {} });
@@ -44,21 +46,20 @@ function App() {
4446
);
4547
}
4648

47-
return <Main data={data} />;
49+
return <Main colorEntity={data.colors[0]} />;
4850
}
4951

50-
const selectId = '4d39508b-9ee2-48a3-b70d-8192d9c5a059';
52+
const selectId = "4d39508b-9ee2-48a3-b70d-8192d9c5a059";
5153

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" };
5556

5657
return (
5758
<View style={[styles.container, { backgroundColor: color }]}>
58-
<View style={styles.spaceY4}>
59+
<View style={[styles.contentSection]}>
5960
<Text style={styles.header}>Hi! pick your favorite color</Text>
6061
<View style={styles.spaceX4}>
61-
{['green', 'blue', 'purple'].map((c) => {
62+
{["green", "blue", "purple"].map((c) => {
6263
return (
6364
<Button
6465
title={c}
@@ -78,20 +79,26 @@ function Main({ data }) {
7879
const styles = StyleSheet.create({
7980
container: {
8081
flex: 1,
81-
justifyContent: 'center',
82-
alignItems: 'center',
82+
justifyContent: "center",
83+
alignItems: "center",
8384
},
8485
spaceY4: {
8586
marginVertical: 16,
8687
},
8788
spaceX4: {
88-
flexDirection: 'row',
89-
justifyContent: 'space-between',
89+
flexDirection: "row",
90+
justifyContent: "space-between",
9091
marginHorizontal: 16,
9192
},
93+
contentSection: {
94+
backgroundColor: "white",
95+
opacity: 0.8,
96+
padding: 12,
97+
borderRadius: 8,
98+
},
9299
header: {
93100
fontSize: 24,
94-
fontWeight: 'bold',
101+
fontWeight: "bold",
95102
marginBottom: 16,
96103
},
97104
});

0 commit comments

Comments
 (0)