1

I have a react component with forwardRef in TypeScript

const MyComponent= <TData, D extends ElementType = TableRowTypeMap['defaultComponent'],P = {}> (props :PropsWithForwardRef<TData, D, P>) => {
   return ()
}

const FinalComponent: (<TData, D extends ElementType = TableRowTypeMap['defaultComponent'],P = {}>(props: PropsWithStandardRef<TData, D, P>) => ReactElement | null) =
    forwardRef<ReactTableRef<any>, ReactTableProps<any, any, any>>((props, ref) => <MyComponent {...props} forwardedRef={ref} />);

export default FinalComponent;

I used This solution to do that, it works fine, but gets a type error (not stopping the application):

Type 'PropsWithForwardRef<any, any, any>' is not assignable to type 'PropsWithForwardRef<TData, D, P>'.

I think the solution is passing TData, D and P, but when I do:

const FinalComponent: (<TData, D extends ElementType = TableRowTypeMap['defaultComponent'],P = {}>(props: PropsWithStandardRef<TData, D, P>) => ReactElement | null) =
    forwardRef<ReactTableRef<TData>, ReactTableProps<TData, D, P>>((props, ref) => <MyComponent {...props} forwardedRef={ref} />);
                             -----                   -----  -  -

I've got error that: Cannot find names TData, D and P !!

Why? and What's the solution?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.