Skip to content

Instantly share code, notes, and snippets.

@stones
Created October 9, 2015 01:36
Show Gist options
  • Save stones/b6c6b3b8ac2a6eee4f98 to your computer and use it in GitHub Desktop.
Save stones/b6c6b3b8ac2a6eee4f98 to your computer and use it in GitHub Desktop.
// Attempting to pass data from 1 child to a separate child of the one parent.
// Is this retarded ?
class Workspace extends Component {
state = {current: 'test'};
setCurrentState(component) {
this.setState({current: component.props.data.title});
}
render() {
return (
<div className="workspace" id="Workspace">
{this.props.components.map((component, index) => {
return (
<WorkspaceComponent data={ component } key={component.objectid} setCurrent={ this.setCurrentState.bind(this) }/>);
})}
<AttributeEditor current={this.state.current }/>
</div>
);
}
}
// Component
class WorkspaceComponent extends Component {
handleClick() {
this.props.setCurrent(this);
}
render() {
return (
<div><button onClick={this.handleClick.bind(this)}>edit</button></div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment