Skip to content

Instantly share code, notes, and snippets.

@nathanforce
Created February 9, 2017 20:07
Show Gist options
  • Save nathanforce/a340800a7e40223a5b36f7667ac885ca to your computer and use it in GitHub Desktop.
Save nathanforce/a340800a7e40223a5b36f7667ac885ca to your computer and use it in GitHub Desktop.
Get ref of child
class Input extends Component {
// other stuff
render() {
return <input value={this.props.value} onChange={this.props.onChange} />
}
};
class CoolComponent extends Component {
// other stuff
doSomethingWithRealInput() {
// do something like copy input value to clipboard
// which requires the input ref
}
render() {
return (
<div>
<button onClick={this.doSomethingWithRealInput}>Do something crazy!!</button>
<Input value={ this.state.value } onChange={ this.update } />
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment