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 ( ) ;
3
16
4
- export default function App ( ) {
5
17
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 >
10
32
) ;
11
- }
33
+ } ) ;
12
34
13
35
const styles = StyleSheet . create ( {
14
36
container : {
@@ -18,3 +40,5 @@ const styles = StyleSheet.create({
18
40
justifyContent : 'center' ,
19
41
} ,
20
42
} ) ;
43
+
44
+ export default App ;
0 commit comments