score:1

Accepted answer

the argument to setstatus should be either:

  • the new value for status

or

  • a function that takes a previous version of status and returns the new version

you are passing it a function that modifies the received value of status, and then returns a boolean value. so it appears that status is changing to that boolean value, and then the status[index] in your classname expression is essentially evaluating true[0], which results in the error.

to fix this, fix your use of the setstatus() function:

setstatus(status => [
    ...status.slice(0, index),     
    event.currenttarget.checked,
    ...status.slice(index + 1)
])

you may also want to try this, which doesn't rely on the event properties:

setstatus(status => [
    ...status.slice(0, index),     
    !status[index],
    ...status.slice(index + 1)
])

or even this:

setstatus(status => 
    status.map((x, i) => (i === index) ? !x : x)
)

Related Query

More Query from same tag