How to catch the row id and delete it?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
12 views
Hello.
I have a table of products, products is an array. By clicking on the Delete button I need to delete the line.
I decided to do this:
  • 1. Make a method to delete(deleteRow)
  • 2. Delete going - to-catch id row, remove the item from the array and rewrite state.


The problem is that I'm confused how would be better:
  • 1. To catch the row id
  • 2. To do the deleteRow method (now it seems to me it was just nonsense)


Here is the code - https://codesandbox.io/s/j1l0y4rmw9
by | 12 views

1 Answer

0 like 0 dislike
Pass deletion method, the index of the deleted item, for example:

deleteRow={() => this.deleteRow(i)}

deleteRow(index) { const productsList = [...this.state.productsList]; productsList.splice(index, 1); this.setState({ productsList }); }
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Jun 14, 2019 by GreyCrew
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users