score:3

Accepted answer

This warning is coming because left or top being NaN. Initialize your left or top to zero or some value in getInitialState Function.

  getInitialState: function() {
    return {
      left:0,
      top: 0
    };

Also cloning React-Element won't help you here. Warning is saying you have to clone your style object when you are making changes to it. Which can be done as

var style1 = {myProp: "value"};
var style2 = Object.assign({}, style1, {newProp:"newValue"}); 

Instead of setting them directly as

<ComponentOne style={{left: this.state.left, top: this.state.top}} /> 

Do in this way

var myStyle = {left: this.state.left, top: this.state.top};
<ComponentOne style={myStyle} /> 

And then based on your changes clone your myStyle object and add changed style properties to it.


Related Query

More Query from same tag