A
A
antpv2018-08-17 20:39:24
React
antpv, 2018-08-17 20:39:24

Why is the React component not updating?

I update the state

this.state = {
      checked: this.props.checked //{1: true, 2: false, 3: false}
    }

Handler:
handleButton = () => {
    let newstate = {1: false, 2: false, 3: false};

    this.setState({
      checked: newstate
    })
  }
}

A rough example for clarity, the only question is why the component is not updated.
React not comparing value of objects in state? The reference to the object seems to be different too. I don't understand

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Sharapenkov, 2018-08-17
@antpv

Comparison goes only by links, superficially. Are you sure the button works? Or try to use a normal bind. There may be many options.
upd.
https://github.com/facebook/react/issues/4618
It says that defaultValue and defaultChecked are set only once during component initialization.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question