在我的文本輸入參考中使用的正確型別是什么?
它在“<TextInput ref <->”行顯示錯誤
const RefComponent = () => {
const inputRef = useRef<HTMLInputElement | null>(null);
return (
<TextInput ref={inputRef} style={{height: 100, width: 500, backgroundColor: 'red', padding: 10}} />
)
};
錯誤:
No overload matches this call.
Overload 1 of 2, '(props: TextInputProps | Readonly<TextInputProps>): TextInput', gave the following error.
Type 'MutableRefObject<HTMLInputElement | null>' is not assignable to type 'LegacyRef<TextInput> | undefined'.
Type 'MutableRefObject<HTMLInputElement | null>' is not assignable to type 'RefObject<TextInput>'.
我做錯了什么?
uj5u.com熱心網友回復:
HTMLInputElement 適用于 web。對于 react-native,您可以使用以下
const inputRef = useRef<typeof TextInput | null>(null);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/433659.html
上一篇:我在reactnative中撰寫了應用程式,但AsyncStorage似乎無法正常作業。當我在手機上重新打開應用程式時,它不記得我之前輸入的內容
