This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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