当我们在父组件中传递ref prop并在子组件中获得prop时,子组件中的typescript中的ref类型是什么?&l



在开始时,我定义了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) => (

为可用的元素类型参考

最新更新