r/reactjs•
swappea

[React - TS] Need help in resolving incompatible types for useRef and forwardRef.

So I am migrating our components to Typescript and we have one set of components regarding Button and Menu. Unfortunately I cannot share the code, but I have tried to recreate the given components on Playcode online.

Here is the link: https://playcode.io/1811917

Now I know forwardRef and mutableRef are not compatible, but not sure how I will handle this scenario.

​

Error: BugFinder: Type 'ForwardedRef<HTMLElement>' is not assignable to type 'MutableRefObject<HTMLElement>'.BugFinder:

Type '(instance: HTMLElement) => void' is not assignable to type 'MutableRefObject<HTMLElement>'.

​

Posted Mar 24, 2024, 9:14 AM UTC

11
Loading comments…