Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

clearing all textInput field on submit react native

$
0
0

i want to clear the all text input field on the button press instead it throws a an error saying undefined is not an option, as trying to take value={this.state.inputTextValue} from and clearing the input setState({inputTextValue : ''})

const[username, setUsername] = useState("");  const[mobile, setMobile] = useState("");  const[ isSubmit, setIsSubmit] = useState(false);  useEffect(() => {    const order = async () => {      axios      .post("*****************",        JSON.stringify({          username:username,          mobile: mobile,        })      )      .then((response) => {        console.log(response.data);        setIsSubmit(false);      })      .catch((err) => {        console.log(err);      });    };    if (isSubmit) order();  }, [isSubmit]);   const orderHandler = (text) => {       setUsername(text);       };  

HERE CLEARING THE TEXTINPUT VALUE ONPRESS

   const handleSubmitEdit = () => {    setState({inputTextValue : ''})  }; return (<ScrollView contentContainerStyle={{flexGrow: 1}}                keyboardShouldPersistTaps='handled'><View style={styles.formwrap}><Form style={styles.mainform}><View style={styles.formgroup}> <SafeAreaView><View style={styles.formItems}>

HERE TAKING VALUE={value={this.state.inputTextValue}}

<TextInput placeholder="Full Name"                        onChangeText={orderHandler}                        value={this.state.inputTextValue}                        /></View><View style={styles.formItems}><TextInput  placeholder="Mobile"                         style={styles.input}                        keyboardType={"phone-pad"}                        onChangeText={(text) => setMobile(text)}                        value={this.state.inputTextValue}                        /></View><View style={styles.buttonContainer}><TouchableOpacity                        style={styles.submit}                        onPress={() => {setIsSubmit(true),handleSubmitEdit()}}'><Text style={[styles.submitText]}>ORDER</Text></TouchableOpacity>                              </View></SafeAreaView>                                            </View>     </Form>                      </View>    </ScrollView>    )};

Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>