0

I have a list of items in my React Native App.

Initially the item's "id" is stored in an array of objects.

enter image description here

Each time i click an item the item's id is removed form the array. Code for id removal:

      let found = this.state.genList.find((a) => a.id === item.id);
      let index = this.state.genList.indexOf(found);
      if (index > -1) {
        this.state.genList.splice(index, 1);
      }
      AsyncStorage.setItem('general_messages', this.state.genList);

Using splice I remove an element with the help of it's index.
This works only ONCE.
The next time I click an item I get the below error.

enter image description here

Why is "splice" causing this issue??
How else could I have written this??
Please help!!

grooot
  • 446
  • 2
  • 10
  • 31
  • splice mutates the array as mentioned in the error message – Dennis Vash Oct 23 '20 at 09:30
  • See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice for details. --> Return value: An array containing the deleted elements. If only one element is removed, an array of one element is returned. If no elements are removed, an empty array is returned. – nologin Oct 23 '20 at 09:34

0 Answers0