Function render after splice and setState()

后端 未结 1 1018
遇见更好的自我
遇见更好的自我 2021-01-22 11:17

I want my React function to re-render after I splice an array.

Here Is (part of) the function (using Hooks):

function showProblem() {
  const [andArray,          


        
1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-22 12:13

    .splice mutates the array. React states have to be immutable. The immuatble way would be:

      setAndState(and.filter((_, i2) => i2 !== i));
    

    0 讨论(0)
提交回复
热议问题