score:4

Accepted answer

the problem you are facing is that you are mutating the state object, which means that at the end, prevstate === nextstate and react bails out of rendering. an option is to use a new object and copy the props like this, using the same combo of object.keys and foreach but adding an extra step:

setstate(prevstate => {
  const nextstate = {}
  object.keys(prevstate).foreach(key => {
    nextstate[key] = true
  })
  return nextstate
})

Related Query

More Query from same tag