Skip to content

Instantly share code, notes, and snippets.

@basarat
Last active February 19, 2016 01:59
Show Gist options
  • Save basarat/8aedc25485694071e919 to your computer and use it in GitHub Desktop.
Save basarat/8aedc25485694071e919 to your computer and use it in GitHub Desktop.
class SelfFocusingInput extends React.Component<{ value: string, onChange: (value: string) => any }, {}>{
ctrls: {
input?: HTMLInputElement;
} = {};
render() {
return (
<input
ref={(input) => this.ctrls.input = input}
value={this.props.value}
onChange={(e) => { this.props.onChange(this.ctrls.input.value) } }
/>
);
}
componentDidMount() {
this.ctrls.input.focus();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment