What’s the react way of setting focus on a particular text field after the component is rendered?
Documentation seems to suggest using refs, e.g:
Set ref=”nameInput” on my input field in the render function, and then call:
this.refs.nameInput.getInputDOMNode().focus();
But where should I call this? I’ve tried a few places but I cannot get it to work.
Kuldeep Baberwal Changed status to publish January 28, 2025
For convenience you can use the AutoForas prop to automatically focus an input when mounted: input autoFocus name=… and this answer is right.\n\nNote that in jsx it\’s autoFocus (capital F) unlike plain old html which is case-insensitive.
Anonymous Changed status to publish January 28, 2025