【发布时间】:2021-01-25 09:12:50
【问题描述】:
我想清除按钮按下时的所有文本输入字段,而不是它抛出一个错误说 undefined 不是一个选项,因为试图从 value={this.state.inputTextValue} 中获取并清除输入 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);
};
在此处清除 TEXTINPUT 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}>
这里取值={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>
)
};
【问题讨论】:
标签: javascript android ios node.js react-native