score:1

Accepted answer

you use useeffect. the useeffect's callback will be triggered when one of dependency is changed.

splice function changes array in place (ie mutates the array). in this case your array variable (showfilter) is not changed, therefore useeffect's callback will not be triggered.

try using filter function instead:

setfilter(showfilter.filter(el=> el !== id));

score:1

splice modifies the original array which is not considered a good practice in react. please use slice or`filter.

using slice your code would look like:

setfilter(showfilter.slice(index, index + 1))

Related Query

More Query from same tag