在开始时,我定义了useRef钩子,然后我把ref变量从父组件传递给子组件中的ref prop。
const weightRef = useRef<TextInput>(null);
<ChildComponent
name={"weight"}
ref={weightRef}
/>
export interface TextInputProps {
name:"string";
ref?: any; //Here what is the type of ref for now i have used any
}
我需要正确的ref类型而不是任何
使用fowardref
传递ref给子组件
export interface TextInputProps {
name:"string";
}
const FancyButton = React.forwardRef<TextInput , TextInputProps>((props, ref) => (
为可用的元素类型参考