score:2

Accepted answer

in the first option you are trying to modify the state directly which is not allowed in react's usestate and that's why it is not rendering your expected change.

the problem with the second option is your are trying to use {} instead of []. try as:

let prevfilters = [ ...filters ];

the reason behind is .map() is a function on arrays and not on objects.


Related Query

More Query from same tag