我有一个反应本机自定义输入组件,并且我成功地将其 ref 转发到父组件。现在,我还想参考孩子本身的输入,我该怎么做?
//my imports here
//my text field component
export const MyTextField = React.forwardRef((props, ref) => {
const [inputValue, setValue] = useState('');
const clearInput = () => {
setValue("");
//I want to get the input by ref here and apply "clear()" method on it
}
return (
<View>
<TextInput
/*
How can i also use this ref to refer to this textinput in The "clearInput" function above
*/
ref={ref}
value={inputValue}
onChangeText={(value) => setValue(value)}
{...props}
/>
<IconButton
icon="close-circle"
onPress={clearInput}
/>
</View>
);
});