单击单选按钮后如何清除文本输入?

时间:2021-05-18 17:58:44

标签: javascript android react-native expo

每当我单击一个选项时,我都希望文本输入被清除 我试过实现 clearbuttonmod 但它不起作用

tcpdump -n -i ens224 not stp

1 个答案:

答案 0 :(得分:1)

在顶部,导入 useRef

import {useRef} from "react";

创建一个 ref 变量并在 TextInput 中使用它

const InputRef = useRef();

然后在 TextInput

 <TextInput
   style={styles.input}
   ref={InputRef}
   clearButtonMode="always"
   placeholder="Report..."
   onChangeText={(value) => setValue(value)}
 />

单选按钮中的广告

<RadioButton.Group
   onValueChange={(value) => {
     setValue(value)
     InputRef.current.clear()
   }}
   value={value}
>

Working Example Here