Created
February 9, 2017 20:07
-
-
Save nathanforce/a340800a7e40223a5b36f7667ac885ca to your computer and use it in GitHub Desktop.
Get ref of child
This file contains hidden or 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
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