Andre Treib's Two Cents

What's New in React 19 RC?

ANAndré Treib

Published on August 30, 2024

React 19 Release Candidate is out, and it's packed with goodies to make your dev life easier. Let’s dive in!

1. Actions: Simplifying Async Updates

React 19 introduces Actions, a game-changer for handling async updates, errors, and form submissions. Imagine a built-in solution for transitions and optimistic UI updates. Here’s a sneak peek:

function SaveButton({ onSave }) {
const saveAction = useActionState(onSave);

return (
<button onClick={saveAction}> {saveAction.pending ? "Saving..." : "Save"} </button>
);
}

No more spinning your wheels with complex state management for async operations!

2. New Hooks for the Win 🪝

Say hello to useActionState, useOptimistic, and useFormStatus. These hooks streamline common scenarios like optimistic updates and form state management. Here’s useOptimistic in action:

function TodoList({ todos }) {
const [optimisticTodos, updateTodos] = useOptimistic(todos);

function addTodo(newTodo) {
updateTodos((prevTodos) => [...prevTodos, newTodo]);
}

return (
<ul> {optimisticTodos.map((todo) => ( <li key={todo.id}>{todo.text}</li> ))} <button onClick={() => addTodo({ id: 4, text: 'New Todo' })}> Add Todo </button> </ul>
);
}

3. Server Components & Actions

React 19 takes server-side rendering to the next level. With Server Components and Server Actions, you can now offload more work to the server:

export default function Page() {
return (
<section> <Header /> <ServerComponent /> </section>
);
}

This makes your app faster and more scalable by reducing client-side complexity.

4. Other Improvements ✨

  • Better ref handling: Simplifies working with refs.
  • <Context> as a provider: A more intuitive way to handle context.
  • Improved hydration error reporting: Makes debugging a breeze.

React 19 is all about reducing boilerplate and increasing your productivity. So, what are you waiting for? Dive in and start experimenting with these shiny new features!

🔗 Check out the full details on React 19 RC

Published on August 30, 2024

André TreibAN