,

The release of React 19 has arrived!

Posted by


After much anticipation, React 19 has finally been released! This new version brings a slew of exciting updates and improvements that will allow developers to create even more powerful and efficient user interfaces. In this tutorial, we’ll walk through some of the key features of React 19 and show you how to get started using it in your own projects.

One of the most significant changes in React 19 is the introduction of automatic batching. In previous versions of React, updates to the virtual DOM were batched by default, but developers were sometimes required to manually batch updates in order to improve performance. However, in React 19, this batching process has been completely automated, meaning that you no longer need to worry about manually batching your updates. This can lead to significant performance improvements in your applications, especially when dealing with complex UI components that require frequent updates.

Another important update in React 19 is the introduction of Suspense for data fetching. Suspense is a feature that allows you to declaratively specify loading states in your components, making it easier to handle asynchronous data fetching operations. With Suspense, you can show loading spinners or fallback content while your data is being fetched, and handle errors gracefully if the fetch fails. This can help to improve the user experience of your applications and make them feel more responsive and polished.

In addition to these major updates, React 19 also introduces several new APIs and hooks that make it easier to work with context and state in your components. The new useContextSelector hook allows you to selectively subscribe to specific context values in your components, reducing unnecessary re-renders and improving performance. The useDeferredValue hook allows you to defer updates to certain values until a later time, helping to optimize rendering performance in your applications.

To get started with React 19, you’ll need to update your project to use the latest version of React. You can do this by running the following command in your terminal:

npm install react@next react-dom@next

Once you’ve updated your project to use React 19, you can start taking advantage of the new features and improvements it offers. Here’s a simple example that demonstrates how to use Suspense for data fetching in a React 19 component:

import { Suspense } from 'react';

const fetchData = () => new Promise((resolve) => {
  setTimeout(() => {
    resolve('Hello, React 19!');
  }, 2000);
});

const DataComponent = () => {
  const data = fetchData();

  return (
    <Suspense fallback={<div>Loading...</div>}>
      <div>{data}</div>
    </Suspense>
  );
};

export default DataComponent;

In this example, we define a fetchData function that returns a Promise that resolves with a simple message after a 2-second delay. We then create a DataComponent that uses the Suspense component to show a loading message while the data is being fetched. When the data is ready, it will be displayed in the component.

Overall, React 19 brings a host of new features and improvements that will help you build even better user interfaces in your applications. By taking advantage of automatic batching, Suspense for data fetching, and the new context and state APIs, you can create more efficient, responsive, and polished UI components that provide a great user experience. So update your projects to React 19 today and start exploring all the exciting possibilities it has to offer!

0 0 votes
Article Rating
44 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@fartune9646
3 months ago

7:54 array does not have any advantages over object in case of using 2 and more actions

@nothingtoseehere5760
3 months ago

I'm learning React, should I bother with 18? It seems like it includes so many redundant things…

@aurorasofie
3 months ago

I’m actively using the use() hook for the promise-part in my project. It’s super use()ful. For example, I have a server component fetching multiple pieces of data. And it contains multiple client components that need this data. I can now call const data = getData, (and I have multiple of these) and pass these promises down, then suspend the client components individually. If I didn’t do this, the whole server component would have to suspend for the await to finish.

@abdoufma
3 months ago

Wait, wasn't the react compiler part of the 19.0 release? 🤔

@olivierromanetti9651
3 months ago

What can I say ? thank you for this tutorial. It took me 3 days to do it and figure it out ha ha. It's very dense, and therefore very stimulating. So thank you again Théo! great content. I'm going to bed less stupid

@igots
3 months ago

Imagine debuging why a page has the wrong meta tag when it's some deeply nested component.

@igots
3 months ago

The title and meta tags stuff is going to cause more grief than people realize.

@Fanaro
3 months ago

React should create a troll hook called `useCase`.

@kralkatorrik34
3 months ago

9:52 You do not need to add underscore. You can just ignore it – `const [,submit, isPending] = useActionState(…)`.

@calo4626
3 months ago

I was taught that hooks should never have if-else conditions before it. I hate to use `use`.

@Fanaro
3 months ago

So much of being a web dev is dealing with forms. It's still super disappointing we have to reinvent the wheel every time.

@Dimonina
3 months ago

Time flies, but nothing changes. All the frameworks introduce features which solve the problems that could be solved with rxjs out of the box many years ago.

@erwile
3 months ago

Can you please stop making dumb clickbait thumbnails?

@garcipat
3 months ago

What happened to the compiler stuff?

@lalibi
3 months ago

What's with the "attributes" pronunciation?

@user-ho4yz2fl3i
3 months ago

At first glance these hooks are somewhat in the direction of react-query

@guseynismayylov1945
3 months ago

Why do I need to load my css by React, if I can preload them in <head> tag via <link rel="preload">.

@phantomhush
3 months ago

Your titles are misleading.

@paxdriver
3 months ago

36:34 prediction – phantom infinite renders one day. Terrible idea. Explicit is better. I'd much prefer a reliable error than an unreliable rare error after deployment.

@paxdriver
3 months ago

Isn't any server component the same as a js file called by the server and the output served by an api? How is that any different from Express? I don't understand all these changes because very few of them seem to serve a need. If shorter code results in less legible code, the more code is better if it's descriptive. I hate shortening code just for the sake of character counts when it makes it take twice as long to figure out the 4 different ways to write the same thing without performance benefits. Nobody is impressed by fewer lines lol I don't like changes when nobody benefits from them, but many people suffer.

Ref should be a built-in prop, not a second arg. If you're gonna need the ref it might as well be a reserved key in props, like why not?