React 19 is now stable ! What’s New 👇
Random

Random @random_ti

About: I'm a self-taught Web developer who is always learning and creating cool Project stuffs.

Location:
India
Joined:
Oct 25, 2023

React 19 is now stable ! What’s New 👇

Publish Date: Dec 8 '24
137 18

React 19 has arrived with exciting new features and improvements!

Hello Dev’s its me Md Taqui Imam, The React 19 is now stable so let’s explore what’s new and how you can use these features in your projects.

This guide will walk you through the most important updates with practical examples.

Follow me in Github⭐


Actions and Form Handling ⭐

Actions are one of the biggest additions in React 19. They make it easier to handle form submissions and data mutations.

function UpdateProfile() {
 const [error, submitAction, isPending] = useActionState(
 async (previousState, formData) => {
 const name = formData.get("name");
 try {
 await updateProfile(name);
 return null; // No error
 } catch (err) {
 return "Failed to update profile";
 }
 },
 null
 );
return (
 <form action={submitAction}>
 <input type="text" name="name" />
 <button type="submit" disabled={isPending}>
 {isPending ? "Updating…" : "Update Profile"}
 </button>
 {error && <p className="error">{error}</p>}
 </form>
 );
}
Enter fullscreen mode Exit fullscreen mode

Using Form Status 🟢

The new useFormStatus hook makes it easy to show loading states:

import { useFormStatus } from 'react-dom';
function SubmitButton() {
 const { pending } = useFormStatus();

 return (
 <button disabled={pending}>
 {pending ? 'Submitting…' : 'Submit'}
 </button>
 );
}
Enter fullscreen mode Exit fullscreen mode

New Hooks 🎉

1. useOptimistic 🆕
This hook helps create instant feedback while waiting for server responses:

import { use } from 'react';
function UserProfile({ userPromise }) {
 const user = use(userPromise);

 return (
 <div>
 <h1>{user.name}</h1>
 <p>{user.email}</p>
 </div>
 );
}
Enter fullscreen mode Exit fullscreen mode

Save it


Document Metadata Support

React 19 now supports metadata tags natively:

function BlogPost({ post }) {
 return (
 <article>
 <title>{post.title}</title>
 <meta name="description" content={post.summary} />
 <link rel="canonical" href={post.url} />

 <h1>{post.title}</h1>
 <p>{post.content}</p>
 </article>
 );
}
Enter fullscreen mode Exit fullscreen mode

Also checkout This Blog


Asset Loading Improvements

New APIs for optimizing resource loading:

import { preload, preinit, preconnect } from 'react-dom';
function App() {
 // Preload important resources
 preload('/fonts/main.woff2', { as: 'font' });
 preinit('/styles/critical.css', { as: 'style' });
 preconnect('https://api.example.com');
return <Main />;
}

Enter fullscreen mode Exit fullscreen mode

Web Components Support

React 19 now fully supports custom elements:

function App() {
 return (
 <div>
 <custom-element
 stringProp="hello"
 numberProp={42}
 objectProp={{ foo: 'bar' }}
 onCustomEvent={(e) => console.log(e.detail)}
 />
 </div>
 );
}
Enter fullscreen mode Exit fullscreen mode

Other Improvements 🛠️

Ref as a Prop

// Old way with forwardRef
const OldInput = forwardRef((props, ref) => (
 <input ref={ref} {props} />
));
// New way in React 19
function NewInput({ ref, props }) {
 return <input ref={ref} {props} />;
}
Enter fullscreen mode Exit fullscreen mode

Better Error Reporting 🔥

React 19 provides clearer error messages and better hydration error reporting:

const root = createRoot(container, {
 onCaughtError: (error) => {
 // Handle errors caught by Error Boundaries
 logError(error);
 },
 onUncaughtError: (error) => {
 // Handle errors not caught by Error Boundaries
 reportFatalError(error);
 }
});
Enter fullscreen mode Exit fullscreen mode

Conclusion / That’s it 😅

React 19 brings many exciting features that make development easier and more efficient. The new form handling capabilities, hooks, and improved asset loading will help developers build better applications with less code.

Remember that while these features are now stable, it’s recommended to test thoroughly when upgrading existing applications to React 19.

For more information, check out the official React 19 announcement and documentation.

And see you in next blog post, till then Byy, Have a Nice Day.

Happy coding!


github

twitter

portfolio

buymeacoffee

Comments 18 total

  • Monty
    MontyDec 8, 2024

    Thanks Dude for the update 🙏

  • Devluc
    DevlucDec 8, 2024

    It's great to see you back at writing Taqui

    • Random
      RandomDec 8, 2024

      Thank you so much sir ! It feels great to be back at it

  • Sirineo Barila
    Sirineo Barila Dec 8, 2024

    I didn't have time to digest react 18 and the 19 version is already out. Too #FastTech?

    • Random
      RandomDec 9, 2024

      Tech moves at lightning speed these days

      • Sirineo Barila
        Sirineo Barila Dec 9, 2024

        Agreed with that!
        By the way I reviewed your GitHub profile and it there is this fun link to one of your project that allow to see how valuation of a developer? I think is pretty good, thought you might want to add social sharing capabilities (linkedin, Reddit...) and an error is thrown when trying to download the image after valuation saying that user have reached the daily download quota.

    • Brad Westfall
      Brad WestfallDec 10, 2024

      React 18 came out over 2.5 years ago

    • Random
      RandomDec 10, 2024

      Thanks 🙌

  • Sakrad CMMI
    Sakrad CMMIDec 10, 2024

    Thanks for updating.

    • Random
      RandomDec 10, 2024

      You'r welcome, i hope you find helpfull 🙌🙌

  • Solomon Ogwu
    Solomon OgwuDec 10, 2024

    Thanks

    • Random
      RandomDec 10, 2024

      🙌🙌🙌

  • Abdullah Nadir
    Abdullah NadirDec 11, 2024

    👍

Add comment