Gol*_*Jer 4 typescript reactjs react-native
如何正确键入 React Native TextInput 的 useRef?
使用以下代码,我收到以下错误。
Property 'isFocused' does not exist on type 'MutableRefObject<TextInput>'
import React, { useRef } from 'react';
import { TextInput } from 'react-native';
const TestScreen = () => {
const searchInputRef = useRef<TextInput>();
const updateSearchText = (searchText: string) => {
console.log(searchTextRef.isFocused()); // Error here.
};
return (
<TextInput
ref={searchInputRef}
placeholder="Search"
onChangeText={(text: string) => updateSearchText(text)}
autoCorrect={false}
autoCapitalize="none"
value={searchText}
/>
)
}
Run Code Online (Sandbox Code Playgroud)
它应该是
const updateSearchText = (searchText: string) => {
console.log(searchInputRef.current.isFocused());
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5824 次 |
| 最近记录: |