I want my input to be locked to focus. I tried this
onBlur={this.click()}
but it didn't work. How do I do it?
give it an autoFocus (camelCase because its react/jsx) attribute
<input type="text" autoFocus/>
if thats what you mean.
The autoFocus attribute is a boolean attribute.
When present, it specifies that an element should automatically get focus when the page loads.
Try this
Use event.target.focus instead of click. You might also want to [invoke this at the end of the event loop][1], i.e. after a timeout of 0ms:
const onBlur = (e) => {
window.setTimeout(() => e.target.focus(), 0);
};
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<input type="text" onBlur={onBlur} />
</div>
);
See proof-of-concept example: