[英]How can I clear Textinput after clicking on radiobutton?
whenever i click an option i want textinput to get cleared i have tried implementing clearbuttonmod but it doesn't work每当我单击一个选项时,我希望清除 textinput 我已经尝试实现 clearbuttonmod 但它不起作用
<View>
<RadioButton.Group
onValueChange={(value) => setValue(value)}
value={value}
>
<RadioButton.Item label="Hate speech" value="Hate speech" />
<RadioButton.Item
label="I just don't like it"
value="I just don't like it"
/>
</RadioButton.Group>
<Text
value=""
style={{
padding: "3%",
fontSize: 18,
}}
>
Others
</Text>
<TextInput
style={styles.input}
clearButtonMode="always"
placeholder="Report..."
onChangeText={(value) => setValue(value)}
/>
on the top, import useRef
在顶部,导入
useRef
import {useRef} from "react";
create a ref
variable and use it in TextInput
创建一个
ref
变量并在TextInput
中使用它
const InputRef = useRef();
then in TextInput然后在 TextInput
<TextInput
style={styles.input}
ref={InputRef}
clearButtonMode="always"
placeholder="Report..."
onChangeText={(value) => setValue(value)}
/>
adn in RadioButton在 RadioButton 中添加
<RadioButton.Group
onValueChange={(value) => {
setValue(value)
InputRef.current.clear()
}}
value={value}
>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.