Skip to content

Commit 6e5e947

Browse files
committed
feat: 🎸 add observer on app
1 parent 4f2abc6 commit 6e5e947

File tree

4 files changed

+41
-12979
lines changed

4 files changed

+41
-12979
lines changed
Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
1-
import { StatusBar } from 'expo-status-bar';
2-
import { StyleSheet, Text, View } from 'react-native';
1+
import { Button, FlatList, SafeAreaView, StyleSheet, Text, View } from 'react-native';
2+
import { state$ } from './src/legend-state';
3+
import { observer } from "@legendapp/state/react";
4+
5+
const App = observer(() => {
6+
7+
const addExpense = () => {
8+
const newExpense = {
9+
id: Math.random().toString(),
10+
title: `Expense ${expenses.length + 1}`,
11+
amount: Math.floor(Math.random()),
12+
};
13+
state$.expenses.set((currentExpenses) => [...currentExpenses, newExpense]);
14+
};
15+
const expenses = state$.expenses.get();
316

4-
export default function App() {
517
return (
6-
<View style={styles.container}>
7-
<Text>Open up App.tsx to start working on your app!</Text>
8-
<StatusBar style="auto" />
9-
</View>
18+
<SafeAreaView style={styles.container}>
19+
<FlatList
20+
data={expenses}
21+
keyExtractor={(item) => item.id}
22+
renderItem={({ item }) => (
23+
<View>
24+
<Text>
25+
{item.title}: ${item.amount}
26+
</Text>
27+
</View>
28+
)}
29+
/>
30+
<Button title="Add Expense" onPress={addExpense} />
31+
</SafeAreaView>
1032
);
11-
}
33+
});
1234

1335
const styles = StyleSheet.create({
1436
container: {
@@ -18,3 +40,5 @@ const styles = StyleSheet.create({
1840
justifyContent: 'center',
1941
},
2042
});
43+
44+
export default App;

0 commit comments

Comments
 (0)