You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've opened #348 to fix this, along with the related problems in the TypeScript output:
The emitted ref prop is now ref?: React.Ref<T> instead of ref: React.RefObject<T>. Optional, and accepting callback refs (including React 19's cleanup-returning form, per @osamaqarem's comment above) as well as ref objects and null.
Union and intersection props/ref types are preserved instead of being silently dropped to an untyped destructure (e.g. forwardRef<HTMLButtonElement | HTMLAnchorElement, PropsWithChildren<Props>>).
Ref parameters annotated with a bare ForwardedRef<T> named import are now recognized too.
I validated this against a ~90-file production migration that previously needed ~500 manual fixes after running this codemod.
If you need this fix before a PR merges, you can run the fixed transform like so:
Notes: --parser=tsx is required (the transform doesn't export a parser), add jsx,js to --extensions if you have untyped files, and run on a clean git tree. You can use --dry --print to show previews without writing.
One heads-up: if your codebase has helper functions typed to accept the old ForwardedRef<T> (e.g. a custom useForwardedRef hook), you'll need to widen those to Ref<T> | undefined by hand afterwards. The call-site-based transformation can't know about them, but tsc will point you at each one.
Activity
osamaqarem commentedon Apr 25, 2025
It also doesn't add the new callback ref type, which is expected by libraries like React Hook Form.
https://react.dev/reference/react-dom/components/common#ref-callback
Fix remove-forward-ref TypeScript output for React 19 (reactjs#336)
adamjcooper commentedon Jul 7, 2026
I've opened #348 to fix this, along with the related problems in the TypeScript output:
ref?: React.Ref<T>instead ofref: React.RefObject<T>. Optional, and accepting callback refs (including React 19's cleanup-returning form, per @osamaqarem's comment above) as well as ref objects andnull.forwardRef<HTMLButtonElement | HTMLAnchorElement, PropsWithChildren<Props>>).ForwardedRef<T>named import are now recognized too.I validated this against a ~90-file production migration that previously needed ~500 manual fixes after running this codemod.
If you need this fix before a PR merges, you can run the fixed transform like so:
Notes:
--parser=tsxis required (the transform doesn't export a parser), addjsx,jsto--extensionsif you have untyped files, and run on a clean git tree. You can use--dry --printto show previews without writing.One heads-up: if your codebase has helper functions typed to accept the old
ForwardedRef<T>(e.g. a customuseForwardedRefhook), you'll need to widen those toRef<T> | undefinedby hand afterwards. The call-site-based transformation can't know about them, buttscwill point you at each one.