delete button react

Solutions on MaxInterview for delete button react by the best coders in the world

showing results for - "delete button react"
Milena
17 Aug 2016
1Let me guess, Are you looking for something like this?
2
3class Example extends React.Component {
4    constructor(){
5    this.state = {
6      data: [
7        {id:1, name: 'Hello'},
8        {id:2, name: 'World'},
9        {id:3, name: 'How'},
10        {id:4, name: 'Are'},
11        {id:5, name: 'You'},
12        {id:6, name: '?'}
13      ]
14    }
15  }
16
17  // shorter & readable 
18  delete(item){
19    const data = this.state.data.filter(i => i.id !== item.id)
20    this.setState({data})
21  }
22
23  // or this way, it works as well
24  //delete(item){
25  //  const newState = this.state.data.slice();
26  //    if (newState.indexOf(item) > -1) {
27  //    newState.splice(newState.indexOf(item), 1);
28  //    this.setState({data: newState})
29  //  }
30  //}
31
32  render(){
33    const listItem = this.state.data.map((item)=>{
34        return <div key={item.id}>
35        <span>{item.name}</span> <button onClick={this.delete.bind(this, item)}>Delete</button>
36      </div>
37    })
38    return <div>
39        {listItem}
40    </div>
41  }
42}
43
44React.render(<Example />, document.getElementById('container'));
45In this example pay attention how i'm binding delete method and pass there new parameter. fiddle
46
47I hope it will help you.
48
49Thanks
queries leading to this page
delete the compnent using delete button i react how to add delete button in react jsreact tag delete buttondelete button reactreact delete button edit and delete button in react jsreact remove button onclickdelete button in onclick reacthow to make delete buttom work in reacthow to change add button to delete in react jsremove button reload reacthandle delete button reacthow to make a delete button function for reactdelete element via button in react jshow to delete button item in reactjsdelating button in reacthow to create button in react that will delete an item with apiedit and delete buttons reactdelete button using reacthow to create delete button reacthow to delete when click on button in reacthow to change add button to delete button in react jsdelete data button react jsremove button in reacthow to make del button in react jsreact delete button onclickdelete button in reactreact delete with buttonreact js delete buttonbutton delete button reactdelete button react jshow to create a delete button in reactfunction of delet button in react jshow to delete a button in reactreact remove buttonsimple react delete button reactdelete button in react jsdelete a button in reactremove button reacthow to delete an item in button reactreact delete button to delete items rendercreate delete buton in reacthow to delete button in reactjsremove item button reactreact button deleteadding a delete button in reacthow delete object wth button in reactdelete button from api reactremove button onclick reactreact should delete button be its own componenthow to add delete button in react natiereact delete self buttonhow to create a delete button in react jsdelete button react