React 19 first beta is out
It's almost 2 years since the last major release of React. The React team has been working on the next major version of React and this week they have released the first beta of React 19.
The key changes
-
React compiler: React 19 introduces a new compiler that will allow React to optimize your code automatically. So you don't need to manually use any of those hooks
memo
,useMemo
anduseCallback
anymore. -
Enhanced hooks: New hooks that will bring big changes.
- forwardRef. The
ref
now is passed as props
- use. This hook will simplify handling promises and other async work.
Another useful usage of this hook is to
use(Context)
.useFormStatus. Finally! You don't need to wrap your submit button to it's own component to get
pending
status. Now it has built in.useFormState. This hook will simplify the form state management.
useOptimistic. This hook will help you to handle optimistic updates.
- forwardRef. The
-
Server components & Actions: React and Nextjs team worked together to bring server components to React. If you are using Nextjs you already used most of these features. And now they are available in React as well with some improvements in DX.
-
Document Metadata: Currently, to change the document metadata you need to use a third-party libraries and write custom code to do that. And finally React 19 brings a new API to handle document metadata. Example:
-
Assets Loading: Usually react developers dealt with "unstyled" flickering on their own using many different methods to prevent that and optimize initial load speed of the application. So they introduced a new Resource Loading APIs like
preload
andpreinit
to provide more control for when a resource should load and initialise, include scripts, stylesheets, and fonts. -
Web components: With React 19 you can use web components in your React applications out of the box.
How to try now?
If you are using typescript you need to install the types as well like so:
For futher information you can check the official blog post. I'm sure we'll see more details about new features and improvements at React Conf on May 15-16.