3

Is there any way I can set value of array in specific index with React imutability helper ?

For example something like this:

   const newState = update(this.state , {
        open[8]:{$set: false}
    })
    this.setState(newState);

or do I have to deep clone that array using JSON and then set new value at specific index and then use react imutability helper to update state?

1
  • You could use { open: state.open.filter((value, index) => index != 8) } Commented Feb 23, 2017 at 20:37

1 Answer 1

7

Assuming your state has the following format:

{
  open: [
    true,
    false,
    true,
    ...
  ]
}

I believe this should work:

const newState = update(this.state , {
  open: {
    8: {$set: false}
  }
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.