Skip to content

Instantly share code, notes, and snippets.

@codeaholicguy
Last active January 21, 2016 04:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save codeaholicguy/fed0f40ba0e5ce0187b3 to your computer and use it in GitHub Desktop.
const OneWayComponent = (props)=> (
<div>
<input value={ props.name } onChange={ (event)=> props.onChange(event.target.value) } />
<p>Hello { props.name }!</p>
</div>
);
class ParentComponent extends React.Component {
constructor() {
super()
this.state = { name: 'Hoang' };
}
change(value) {
this.setState({name: value});
}
render() {
return (
<div>
<OneWayComponent name={ this.state.name } onChange={ this.change.bind(this) } />
<p>Hello { this.state.name }!</p>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment