I have an input text field . When a user inputs any text and clicks enter button I need to activate the blur event to remove the focus and also to validate the textinput .
<input type="text"
style={{marginTop:'20%', marginLeft:'40%'}}
value={value}
onFocus={onFocus}
onChange={e => setValue(e.target.value)}
onKeyPress={handleKeyPress}
/>
Avoid using refs for anything that can be done declaratively.
andDon’t Overuse Refs
-reactjs.org/docs/refs-and-the-dom.html – Errick