Answers for "clear textinput react native"

1

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.

	/>
 )
Posted by: Guest on February-11-2021
0

Clear React Native TextInput

const [text, setText] = useState('');
 const anotherFunc = (val) =>{
        setText('');
    }


    return (
        <View>
            <TextInput 
            value ={text}
            onChangeText ={changeHander}
            placeholder = 'Add '
           />
            <Button 
            title = "Add Something "
            onPress = {()=>  {submitHandler(text) , anotherFunc(text)}}
            />

        </View>
    )
Posted by: Guest on September-25-2021

Code answers related to "clear textinput react native"

Code answers related to "Javascript"

Browse Popular Code Answers by Language