Your EditorCanvas expects its points
array in its state to be the source of truth, but the changes in Toolbar are not making it back to that array. The Toolbar creates its own state, which is not persisted to the EditorCanvas. I suggest keeping all state in EditorCanvas and passing the changes from the Toolbar to the canvas with a callback.
Working JSFiddle: http://jsfiddle.net/krza5/2/
var EditorCanvas = React.createClass({
getInitialState: function() {
return {
points: [
{
x: 50,
y: 100
},
{
x: 200,
y: 50
}
],
selected: null
};
},
render: function() {
return <div>
<Toolbar point={this.state.selected}
onXChange={this.setSelectedX}
onYChange={this.setSelectedY}/>
<div id="canvas">
{this.state.points.map(this.renderPoint)}
</div>
</div>;
},
renderPoint: function(point) {
return <Point point={point} onClick={this.selectPoint.bind(this, point)}/>
},
selectPoint: function(point) {
this.setState({selected: point});
},
setSelectedX: function(event) {
var point = this.state.selected;
point.x = event.target.value;
this.forceUpdate();
},
setSelectedY: function(event) {
var point = this.state.selected;
point.y = event.target.value;
this.forceUpdate();
}
});
var Toolbar = React.createClass({
render: function() {
var point = this.props.point;
if (!point) {
return <div id="toolbar"/>;
}
return <div id="toolbar">
x:<input type="number" value={point.x} onInput={this.props.onXChange}/>
·
y:<input type="number" value={point.y} onInput={this.props.onYChange}/>
</div>;
}
});
var Point = React.createClass({
render: function() {
var style = {
left: this.props.point.x + 'px',
top: this.props.point.y + 'px'
};
return <div style={style} className="point" onClick={this.props.onClick}/>
}
});