Use A Ref To Autofocus An Input
class MyAutofocusInput extends React.Component {
focusInput = (component) => {
if (component) {
component.focus();
}
};
render() {
return (
<input
ref={this.focusInput}
value={this.props.value}
onChange={this.props.onChange}
/>
);
}
}Last updated