How to know when the focus is lost in a react native textInput?
Sophia Terry
How to know when the focus is lost in a react native textInput?
For example I want to do an action when the user touches outside the textInput and it loses focus.
03 Answers
use the onBlur prop on TextInput
example
<TextInput onFocus={() =>console.log("focus received" ) } onBlur={() => console.log("focus lost") } /> The prop you are looking for is the onBlur. This is called when it loses focus.
You need to use the onBlur prop on TextInput.
example
onBlurMethod = () =>{ //what you want to do when it is not focused
}
<TextInput onBlur = {this.onBlurMethod}
/>