Try to search your question here, if you can't find : Ask Any Question Now ?

How to modify the value of an array of Bool in React

HomeCategory: stackoverflowHow to modify the value of an array of Bool in React
pushpa asked 2 weeks ago

I have an array of boolean as a state in my component. If it is false, I want to set it as true.

this.state = {
       checkedPos: []
}


handleChange(index, reaction) {
if (!this.state.checkedPos[index])
    {
      this.state.checkedPos[index] = true;
      this.addReaction(reaction);
      this.forceUpdate();
    }
}

It works, but the only problem I encounter is that it show this warning:

Do not mutate state directly. Use setState()

So I tried changing it and putting it like this:

this.setState({
 checkedPos[index]: true
})

But it does not compile at all.

1 Answers
Best Answer
Arben answered 2 weeks ago
Your Answer

4 + 14 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com