SHARE
TWEET

Untitled

a guest Jun 15th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class App extends Component {
  2.    state = {
  3.       todos: [
  4.          { todo: 'go to gym', id: 1 },
  5.          { todo: 'buy a mouse', id: 2 },
  6.          { todo: 'practice hash table', id: 3 },
  7.          { todo: 'iron clothes', id: 4 },
  8.       ]
  9.    }
  10.  
  11.    keyExtractor = (item) => item.id.toString()
  12.  
  13.    handleDelete = (id) => {
  14.       const todos = this.state.todos.filter(item => item.id !== id)
  15.       this.setState({ todos })
  16.    }
  17.  
  18.    renderItems({ item }) {
  19.       return (
  20.          <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}>
  21.             <Text style={{ fontSize: 16 }}>{item.todo}</Text>
  22.             <TouchableOpacity onPress={() => this.handleDelete(item.id)} style={{ marginRight: 15 }}>
  23.                <Text style={{ color: 'red' }}>Delete</Text>
  24.             </TouchableOpacity>
  25.          </View>
  26.       )
  27.    }
  28.  
  29.    render() {
  30.       return (
  31.          <View>
  32.             {/* {this.renderItems()} */}
  33.             <FlatList
  34.                data={this.state.todos}
  35.                keyExtractor={this.keyExtractor}
  36.                renderItem={this.renderItems}
  37.             />
  38.          </View>
  39.       );
  40.    }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top