Skip to content

Commit f16fefc

Browse files
committed
lesson-10
1 parent 54b986e commit f16fefc

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

my-project/App.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState } from 'react';
22
import { StyleSheet, Text, View, FlatList } from 'react-native';
33
import Header from './components/header';
4+
import TodoItem from './components/todoItem';
45

56
export default function App() {
67
const [todos, setTodos] = useState([
@@ -9,6 +10,11 @@ export default function App() {
910
{ text: 'play on the switch', key: '3' }
1011
]);
1112

13+
const pressHandler = (key) => {
14+
setTodos(prevTodos => {
15+
return prevTodos.filter(todo => todo.key != key);
16+
});
17+
};
1218

1319
return (
1420
<View style={styles.container}>
@@ -19,7 +25,7 @@ export default function App() {
1925
<FlatList
2026
data={todos}
2127
renderItem={({ item }) => (
22-
<Text>{item.text}</Text>
28+
<TodoItem item={item} pressHandler={pressHandler} />
2329
)}
2430
/>
2531
</View>

my-project/components/todoItem.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react'
2+
import {StyleSheet, TouchableOpacity, Text} from 'react-native';
3+
4+
export default function TodoItem({ pressHandler, item }) {
5+
return (
6+
<TouchableOpacity onPress={() => pressHandler(item.key)}>
7+
<Text style={styles.item}>{item.text}</Text>
8+
</TouchableOpacity>
9+
)
10+
}
11+
12+
const styles = StyleSheet.create({
13+
item: {
14+
padding: 16,
15+
marginTop: 16,
16+
borderColor: '#bbb',
17+
borderWidth: 1,
18+
borderStyle: "dashed",
19+
borderRadius: 1,
20+
borderRadius: 10,
21+
}
22+
});

0 commit comments

Comments
 (0)