File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 11import React , { useState } from 'react' ;
22import { StyleSheet , Text , View , FlatList } from 'react-native' ;
33import Header from './components/header' ;
4+ import TodoItem from './components/todoItem' ;
45
56export 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 >
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments