React 19 is Officially Stable: Discover the Latest Features and Updates

Chris BolosanChris Bolosan
4 min read

React 19: Everything You Need to Know with Simple Examples

React 19 is here and it’s packed with awesome new features that make development easier and apps faster. Let’s break down the coolest updates, how they work, and how you can start using them right away with straightforward examples to guide you.

What’s New in React 19

1. Server Actions and useActionState()

Server Actions let React handle server-side stuff (like database updates or API calls) right inside your components. This makes life way easier by cutting down on all the back-and-forth between the client and server.

Example: Server Actions with useActionState()

'use client';

import { useActionState } from 'react';

async function saveUserData(data) {
  const response = await fetch('/api/save-user', {
    method: 'POST',
    body: JSON.stringify(data),
  });
  return response.json();
}

export default function UserForm() {
  const action = useActionState(saveUserData);

  const handleSubmit = async (e) => {
    e.preventDefault();
    const formData = new FormData(e.target);
    await action(formData);
  };

  return (
    <form onSubmit={handleSubmit}>
      <input name="username" placeholder="Enter your name" />
      <button type="submit" disabled={action.isPending}>
        {action.isPending ? 'Saving...' : 'Save'}
      </button>
    </form>
  );
}

This shows how to save user info to a server and display a "Saving..." message while it’s working.

2. Custom Elements

React 19 makes it super easy to use custom web components (like third-party widgets) in your apps. No hacks or extra setup needed.

Example: Using a Custom Element

function App() {
  return (
    <div>
      <my-custom-button>
        Click Me
      </my-custom-button>
    </div>
  );
}

This is great for reusable or third-party widgets you want to add to your app.

3. Automatic Batching

React 19 can now group multiple state updates into one render, which means smoother performance without any extra effort from you.

Example: Automatic Batching

import React, { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);
  const [text, setText] = useState('');

  const handleClick = () => {
    setCount((prev) => prev + 1);
    setText(`Count is now ${count + 1}`);
  };

  return (
    <div>
      <p>{text}</p>
      <button onClick={handleClick}>Increment</button>
    </div>
  );
}

Both setCount and setText run together, so React only re-renders once instead of twice.

4. Better Suspense for Loading States

Suspense is now even better at handling things like loading screens while waiting for data or components to load.

Example: Data Fetching with Suspense

import React, { Suspense } from 'react';

const UserProfile = React.lazy(() => import('./UserProfile'));

function App() {
  return (
    <Suspense fallback={<div>Loading...</div>}>
      <UserProfile />
    </Suspense>
  );
}

While UserProfile is loading, you’ll see a simple "Loading..." message.

5. The use() Hook for Async Stuff

The new use() hook makes it super easy to deal with async operations inside components, keeping your code clean and simple.

Example: Fetching Data with use()

async function getUserData() {
  const response = await fetch('/api/user');
  return response.json();
}

function Profile() {
  const user = use(getUserData());

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

Instead of juggling states and effects, you just call use(). It’s that simple.

6. Easier DOM Control with Refs

React 19 makes working with refs even better. You can pass them as props or use callback refs for more advanced scenarios.

Example: Using Ref Callbacks

import React, { useRef, useEffect } from 'react';

function App() {
  const inputRef = useRef();

  useEffect(() => {
    inputRef.current.focus();
  }, []);

  return <input ref={inputRef} placeholder="Focus on load" />;
}

Want an input to auto-focus when the page loads? This example shows you how.

7. Better Meta Tags for SEO

If you’re building server-rendered apps, React 19 makes it easier to manage meta tags for better search engine optimization (SEO).

Example: Adding Meta Tags

import { Helmet } from 'react-helmet';

function SEOComponent() {
  return (
    <Helmet>
      <title>React 19 Features</title>
      <meta name="description" content="Learn about React 19 features." />
    </Helmet>
  );
}

Why React 19 is Faster

With smarter rendering (like automatic batching and optimized Suspense), apps built with React 19 load faster and feel snappier. Benchmarks show that it cuts down rendering times by up to 30%, which is huge for complex apps.

How to Upgrade to React 19

  1. Install the latest version:
    Run npm install react@19 react-dom@19.

  2. Check the changelog:
    Look out for anything that’s been deprecated and update your code accordingly.

  3. Test your app:
    Always run your app in a staging environment before going live.

Final Thoughts

React 19 is packed with features that make building apps easier and faster. From handling server-side logic to smarter rendering, this version has something for everyone. Try out these features today and take your React projects to the next level!

0
Subscribe to my newsletter

Read articles from Chris Bolosan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Chris Bolosan
Chris Bolosan

I’m a Software Engineer in the Chicago area interested in building products that drive positive change. I am comfortable working both independently and as part of a team. When I’m not coding, you can find me helping others in the martial arts community, working on DIY home projects, tinkering with cars, or cooking up a new recipe. My expertise is in Southern-style BBQ. If you’d like to talk code, cars, food, or just plain building stuff, shoot me a message.