React 19 Update - Is React Great Again?

In this post, I'd like to discuss React 19 and what we can expect next from React.

blog post

Here, I've opened the official blog post on react.dev. The latest post was made on February 15, 2024. It's worth noting that we haven't received any updates in React for almost a year, which is quite a long time for such a popular framework.

React 19 has not been released yet, and a specific release date has not been announced.

However, here are all the features and updates that we can expect to see in React 19.

React Compiler

The most important part is the React Compiler. What is it about? The React Compiler is a solution within React that enables it to better understand code and minimize unnecessary rerenderings.

In React, we often experience rerenderings whenever something changes, such as state. However, we typically use optimization techniques like useMemo or useCallback to reduce the number of unnecessary rerenderings in our components.

The main idea behind the React Compiler is to enhance React's ability to understand our code and avoid these unnecessary rerenderings. This implies that in the future, we may not need to use useMemo or useCallback as extensively as we do now.

Most importantly, we don't need to make any changes to our code, as the React Compiler modifies React internally while keeping the entire API unchanged.

To allow the React Compiler to optimize your code effectively, it must be written in the best possible way. How can you achieve this? By adhering to the guidelines provided by React. The easiest way to ensure compliance is by enabling React strict mode and using the React ESLint plugin. These tools provide warnings when code is written incorrectly or deviates from best practices.

However, even if you don't follow these guidelines, it doesn't necessarily mean that your project will be completely broken. The React Compiler will simply refrain from optimizing the affected code.

eslint plugin

Similarly to dealing with issues in useEffect, it's highly beneficial to install the ESLint plugin and pay attention to the warnings provided by React. This helps ensure that your code aligns with best practices and is optimized for the React Compiler.

It's also important to note that the React Compiler is not a beta solution, indicating that it's a stable and mature feature within React.

It's worth mentioning that the React Compiler is already being used in production at Instagram. This underscores its reliability and effectiveness in real-world applications.

This essentially means that a large-scale production application like Instagram is successfully leveraging the new React Compiler without any issues.

Actions

Another important feature we're getting is called "Actions" or "Server Actions". This functionality, already present in Next.js, is considered stable as it's based on experimental features.

<form action={search}>
  <input name="query" />
  <button type="submit">Search</button>
</form>

The main idea behind "Actions" or "Server Actions" is to securely send data from the client to the server and perform database requests. This feature is complemented by hooks such as useFormStatus and useFormState, which you might already be familiar with from Next.js tutorials.

useOptimistic Hook

In addition to that, we're also getting the useOptimistic hook. This hook is designed to facilitate optimistic updates in your code. It enables you to display the result of your API call to the user immediately upon receiving the response from the API.

Currently, implementing optimistic updates manually is common practice. However, with this hook, the process will be much simpler as it handles it for us.

When?

All these features are already implemented in React Canary, a special version of React that allows you to access these new functionalities. However, they have not yet been merged into the official React branch.

In addition to these updates, React server components are also expected to be introduced. I've previously written a post about this, where I discuss features like useClient or useServer, which enable the creation of components designed specifically for either server-side or client-side rendering.

Server React components are already available by default in Next.js, making it convenient to test them out and explore their capabilities.

Furthermore, if you've ever needed to modify your title or meta information, you may have used the React Helmet library. However, with the new functionality directly integrated into React, such additional libraries like React Helmet will no longer be necessary.

Want to conquer your next JavaScript interview? Download my FREE PDF - Pass Your JS Interview with Confidence and start preparing for success today!

Did you like my post? Share it with friends!
Don't miss a thing!
Follow me on Youtube, Twitter or Instagram.
Oleksandr Kocherhin
Oleksandr Kocherhin is a full-stack developer with a passion for learning and sharing knowledge on Monsterlessons Academy and on his YouTube channel. With around 15 years of programming experience and nearly 9 years of teaching, he has a deep understanding of both disciplines. He believes in learning by doing, a philosophy that is reflected in every course he teaches. He loves exploring new web and mobile technologies, and his courses are designed to give students an edge in the fast-moving tech industry.