react-native add clear textinput code example
Example: clear textinput react native
"CLEAR TEXT FROM INPUT FIELD IN REACT NATIVE, WHEN CLICK SUBMIT BUTTON"
const [textInput, setTextInput] = useState() //this state always holds the text
const submitHandler = () => { //runs on submit and sets the state to nothing.
setTextInput("")
}
const changeHandler = (value) => { //grabs textinput value and puts it in state
setTextInput(value);
}
return(
<TextInput
onSubmitEditing={submitHandler} //when click on "done" button on keyboard
onChangeText={changeHandler} //when text is changed, add it to the state.
value={textInput} //text inside is always the same as in our state.
/>
)