A simple example:
class Element extends Component { constructor(props) { super(props); this.state = { name: props.name } } render() { return <p>{this.state.name}</p> } } class Elements extends Component { constructor(props) { super(props); this.state = { names: props.names } } render() { return <div>{ this.state.names.map(function(name, i) { return <Element key={ i } name={ name } /> }) }</div> } componentWillMount() { setTimeout( () => { this.state.names.splice(1, 1); let names = this.state.names; this.setState({names: names}); }, 3000 ); } } ReactDOM.render( <Elements names={ [0, 1, 2] } />, document.body ); In general, create the Element . It takes the name in the properties. We write name in the state name . And display the state name .
Elements takes in the names property - the name array for the Element . names writes to its state names . The names state passes in the output and for each creates an Element , passing the next name to the properties to it.
Further setTimeout is just for example, no matter how, but the state of the names of Elements changes. Any name is removed from it. As a result, all Elements are redrawn and each has its own name property. But the state name does not change.
Began to check - yes, the constructor does not work when the Element is redrawn. ComponentWillMount too. ComponentWillUnmount works for one element, but not for the one that was deleted, but for the latter for some reason.
In short, in the end everything looks like this: First on the monitor 0 1 2 and then 0 1 . A must be 0 2 .
Neither can I understand why this is happening ...