React 19 Simplifies Refs with Standard Prop

⚛️ forwardRef is finally dead in React 19 👇 . For years, if you wanted to pass a ref to a child component, you had to wrap it in a Higher-Order Component called forwardRef. It made your code verbose, complicated TypeScript definitions, and broke component composition. React 19 treats ref as a standard prop. ❌ The Old Way: Wrap your component: forwardRef((props, ref) => ...) It was a special case that required special syntax. ✅ The Modern Way: Just destructure ref from props: function Input({ ref }). It behaves exactly like className or id. • No Wrappers: Pure function components. • Better Types: No more ForwardRefRenderFunction<T, P>. • Simple: It just works. The Shift: We are removing "React Magic" and returning to "Just JavaScript." What about TypeScript? 📘 This is a huge win for TS users. Previously, typing forwardRef was a pain (you had to swap the order of Generics and Props). Now? You just type it like a normal prop: interface Props { ref: React.Ref<HTMLInputElement>; ... } Much more readable! #ReactJS #React19 #WebDevelopment #JavaScript #CleanCode #SoftwareEngineering #TechTips #Tips #ReactHooks #Hooks #ReactTips #FrontrendDeveloper #DevloperTips #TypeScript

  • graphical user interface, text, application, chat or text message

it's not true that is't dead. It's even not deprecated yet

Like
Reply

Make sure to pass ref in props separately not pull it out from props, otherwise it won't work. Thanks

See more comments

To view or add a comment, sign in

Explore content categories