1

In start i have define the useRef Hook and then i have passed ref variable to ref prop in the child component form the parent component.

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
}

I need correct type of ref instead of any

Faizan Ali
  • 37
  • 5
  • In any decent IDE, and in the [TypeScript playground](https://www.typescriptlang.org/play), you can get the answer to this kind of question by hovering your mouse over `weightRef` in your first line of code above. It would show `MutableRefObject`. – T.J. Crowder Dec 14 '22 at 09:36

1 Answers1

0

use fowardref to pass ref to child component

export interface TextInputProps {
  name:"string"; 
}


const FancyButton = React.forwardRef<TextInput , TextInputProps>((props, ref) => (

refer this for available element types

Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80