-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
58 lines (49 loc) · 1.17 KB
/
App.tsx
File metadata and controls
58 lines (49 loc) · 1.17 KB
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
import React, {useState} from 'react';
import {SafeAreaView, StyleSheet, Text} from 'react-native';
import RadioGroup from './RadioGroup';
export type Item = {
id: number;
name: string;
};
export type RadioGroupProps = {
items: Item[];
selected?: Item;
onSelected(item: Item): void;
};
export type RadioButtonProps = {
item: Item;
selected?: Item;
onSelected(item: Item): void;
};
const App = () => {
const [selected, setSelected] = useState<Item>();
const items: Item[] = [
{id: 1, name: 'Apple'},
{id: 2, name: 'Orange'},
{id: 3, name: 'Kiwi'},
{id: 4, name: 'Watermelon'},
{id: 5, name: 'Strawberry'},
{id: 6, name: 'Cherry'},
];
const onSelected = (item: Item) => {
setSelected(item);
};
return (
<SafeAreaView style={styles.container}>
<Text style={styles.header}>
Please select an item: {selected ? selected.name : 'Nothing selected'}
</Text>
<RadioGroup selected={selected} onSelected={onSelected} items={items} />
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
header: {
padding: 10,
},
});
export default App;