This warning appears because left
or top
NaN
. Initialize your left or top zero or some value in the getInitialState Function
.
getInitialState: function() { return { left:0, top: 0 };
Also, cloning React-Element will not help you. The warning says that you should clone your style object when you make changes to it. What can be done as
var style1 = {myProp: "value"}; var style2 = Object.assign({}, style1, {newProp:"newValue"});
Instead of installing them directly as
<ComponentOne style={{left: this.state.left, top: this.state.top}} />
Do so
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 the changed style properties to it.
source share