1 "CLEAR TEXT FROM INPUT FIELD IN REACT NATIVE, WHEN CLICK SUBMIT BUTTON"
2
3 const [textInput, setTextInput] = useState() //this state always holds the text
4 const submitHandler = () => { //runs on submit and sets the state to nothing.
5 setTextInput("")
6 }
7 const changeHandler = (value) => { //grabs textinput value and puts it in state
8 setTextInput(value);
9 }
10 return(
11
12 <TextInput
13 onSubmitEditing={submitHandler} //when click on "done" button on keyboard
14 onChangeText={changeHandler} //when text is changed, add it to the state.
15 value={textInput} //text inside is always the same as in our state.
16
17 />
18 )
19
20
1const [text, setText] = useState('');
2 const anotherFunc = (val) =>{
3 setText('');
4 }
5
6
7 return (
8 <View>
9 <TextInput
10 value ={text}
11 onChangeText ={changeHander}
12 placeholder = 'Add '
13 />
14 <Button
15 title = "Add Something "
16 onPress = {()=> {submitHandler(text) , anotherFunc(text)}}
17 />
18
19 </View>
20 )
21