What’s New in React 19: Discover the Latest Features and Enhancements
Share on:
Date: 09 Dec 2024
Introduction
React 19, the latest version of the popular JavaScript library for building user interfaces, was officially released on December 5, 2024. This release brings a host of new features, improvements, and optimizations aimed at enhancing the developer experience and improving web app performance. Whether you’re a seasoned React developer or just starting, there’s something in React 19 for everyone.
Key Features of React 19
New Hooks and APIs: React 19 introduces several new hooks and APIs that simplify state management and component lifecycle handling, making your code more concise and easier to maintain.
React Server Components: This powerful new feature allows you to build modern, dynamic web applications with less client-side JavaScript, resulting in faster load times and improved performance.
Full Support for Custom Elements: React 19 now fully supports custom elements, enabling seamless integration with web components and allowing for greater flexibility in your app architecture.
Performance Improvements: Various under-the-hood optimizations have been made to enhance the performance of React applications, ensuring a smoother and more responsive user experience.
Stay tuned for more detailed insights into each of these features, along with code examples to help you get started with React 19.
React DOM: <form> Actions
React 19’s new <form> features for react-dom now include Actions, enabling developers to pass functions as the action and formAction props of <form>, <input>, and <button> elements. This integration allows for automatic form submission with Actions.
useFormStatus reads the status of the parent <form> as if the form was a Context provider.
New API: use
React 19 introducing a new API to read resources in render: use
For example, you can read a promise with use, and React will Suspend until the promise resolves:
import {use} from 'react';function Comments({commentsPromise}) { // `use` will suspend until the promise resolves. const comments = use(commentsPromise); return comments.map(comment =>{comment}); } function Page({commentsPromise}) { // When `use` suspends in Comments, // this Suspense boundary will be shown. return (<div>Loading...</div>}>)}
Another common UI pattern when performing a data mutation is to show the final state optimistically while the async request is underway. In React 19, we’re adding a new hook called useOptimistic to make this easier:
Server Components
Server Components allow pre-rendering components before bundling, in a separate environment from your client app or SSR server. They can run at build time on your CI server or for each request via a web server.
React 19 includes all React Server Components features from the Canary channel. Libraries with Server Components can now target React 19 as a peer dependency with a react-server export condition for full-stack React frameworks.
Server Actions
Server Actions allow Client Components to call async functions on the server. When defined with the „use server” directive, the framework creates a server function reference and passes it to the Client Component. When called, React sends a request to the server to execute the function and returns the result.
Note: There is no „use server” directive for Server Components; it is used only for Server Actions.
Server Actions can be created in Server Components and passed as props to Client Components or imported directly.
For more details, see the docs for React Server Actions.
ref as a prop
Starting in React 19, you can now access ref as a prop for function components:
React 19 now support returning a cleanup function from ref callbacks:
<input ref={(ref) => { // ref created // NEW: return a cleanup function to reset // the ref when element is removed from DOM. return () => { // ref cleanup }; }}/>
Document Metadata Hoisting
In HTML, tags like <title>, <link>, and <meta> are typically placed in thesection of the document. However, in React, the component responsible for setting these metadata tags might be far from where theis rendered, or themight not be rendered at all. Previously, developers had to manually insert these elements using effects or libraries like react-helmet, especially when server rendering React applications.
With React 19, document metadata tags can now be natively rendered within components. This is a straightforward yet highly useful update, as metadata in your components will be automatically hoisted to the document’ssection.
function BlogArticle({article}) { return ( <article> <h1>{article.title}</h1> <title>{article.title}</title> <meta name="author" content="fireup.pro" /> <meta name="description" content={article.description} /> <meta name="keywords" content={article.keywords} /> <p> Article content, one two three... </p> </article> );}
Support for stylesheets
Stylesheets, whether external (<link rel="stylesheet">) or inline (<style>), need careful DOM positioning due to style precedence rules. This complexity often forces users to load all styles far from dependent components or use encapsulating style libraries.
React 19 simplifies this with built-in support for stylesheets, integrating into Concurrent and Streaming Rendering. By specifying stylesheet precedence, React manages the insertion order and ensures external styles load before dependent content is revealed.
function ComponentOne() { return ( <Suspense fallback="loading..."> <link rel="stylesheet" href="foo" precedence="default" /> <link rel="stylesheet" href="bar" precedence="high" /> <article class="foo-class bar-class"> {...} </article> </Suspense> )}function ComponentTwo() { return ( <div> <p>{...}</p> <link rel="stylesheet" href="baz" precedence="default" /> <-- will be inserted between foo & bar </div> )}
Support for preloading resources
Informing the browser about necessary resources as early as possible during the initial document load and client-side updates can significantly boost page performance. React 19 introduces several new APIs for efficient loading and preloading of browser resources, simplifying the process of creating fast and seamless user experiences without being hampered by slow resource loading.
import { prefetchDNS, preconnect, preload, preinit } from 'react-dom'function MyComponent() { preinit('https://.../path/to/some/script.js', {as: 'script' }) // loads and executes this script eagerly preload('https://.../path/to/font.woff', { as: 'font' }) // preloads this font preload('https://.../path/to/stylesheet.css', { as: 'style' }) // preloads this stylesheet prefetchDNS('https://...') // when you may not actually request anything from this host preconnect('https://...') // when you will request something but aren't sure what}
<!-- the above would result in the following DOM/HTML --><html> <head> <!-- links/scripts are prioritized by their utility to early loading, not call order --> <link rel="prefetch-dns" href="https://..."> <link rel="preconnect" href="https://..."> <link rel="preload" as="font" href="https://.../path/to/font.woff"> <link rel="preload" as="style" href="https://.../path/to/stylesheet.css"> <script async="" src="https://.../path/to/some/script.js"></script> </head> <body> ... </body></html>
Support for async scripts
In HTML, normal and deferred scripts load in document order, making deep component tree rendering challenging, while async scripts load in arbitrary order.
React 19 enhances support for async scripts, allowing them to be rendered anywhere in the component tree. This avoids the need to manage script relocation and deduplication.
Async scripts are deduplicated across all rendering environments, ensuring they load and execute only once, even if rendered by multiple components. In Server Side Rendering, async scripts are included in theand prioritized behind critical resources like stylesheets, fonts, and image preloads.
Those are just a few of the highlights! Other changes include:
New hook: useActionState
New React DOM Static APIs prerender , prerenderToNodeStream
Better error reporting
Support for Custom Elements
Diffs for hydration errors
Compatibility with third-party scripts and extensions
Rate the article!
0
5 ratings, avg: 5
fireup.pro team
The presented content was written by our experts and is based on our company's experiences.
Microfrontends are transforming how modern web applications are built, enabling teams to develop and deploy independent features without impacting the entire application. In this article, we’ll explore how to set up microfrontends using Nx, a powerful monorepo tool, with detailed examples and explanations. By the end, you’ll have a clear understanding of how to leverage […]
In the fast-paced world of web development, maintaining clean and error-free code is crucial. This is where Biome comes into play, offering a comprehensive toolchain that combines formatting and linting to streamline your workflow. Let’s dive into the features and benefits of Biome and how it can elevate your web projects. What is Biome? Biome […]
Maximize Your Web App’s Performance with Vercel Observability In today’s digital landscape, where website performance directly correlates with user satisfaction and SEO rankings, developers need tools that not only monitor but also enhance application performance. Vercel Observability emerges as a game-changer, providing a comprehensive suite of tools designed to bring your web applications to their […]
Amazon Aurora DSQL: The Future of Serverless Databases ? Introduction Amazon Aurora DSQL, unveiled at AWS re:Invent 2024, is the latest innovation in serverless, distributed SQL databases. Designed to meet the demands of modern applications, Aurora DSQL promises virtually unlimited scalability, high availability, and robust performance, all while maintaining PostgreSQL compatibility. Main Advantages of Amazon […]
Build Native Windows Apps with Ease Introduction In the ever-evolving world of software development, the need for efficient cross-platform solutions has never been greater. Enter React Native for Windows, a powerful framework that enables developers to build native Windows applications using the familiar JavaScript and React ecosystem. What is React Native for Windows? React Native […]
Supermaven is an advanced AI-powered code completion tool designed to enhance developer productivity with its fast, high-quality code suggestions. It’s compatible with popular code editors like VS Code, JetBrains IDEs, and Neovim. Supermaven uses a 1 million token context window to provide the highest quality code completions, making it a powerful tool for developers. Jacob […]
The animation library, previously known as Framer Motion, is now rebranded as Motion and is set to expand its reach beyond React. Why the Change? The decision to spin off Motion as an independent project stems from its success and the community’s demand for broader accessibility. Over the years, Motion has become a go-to solution […]
Revolutionize Your Frontend Testing with Meticulous.ai In the world of web development, ensuring the consistency and reliability of your user interface (UI) is crucial. Enter Meticulous.ai, a cutting-edge tool designed to streamline and enhance frontend testing. By leveraging automated visual regression testing, Meticulous.ai promises to make your development process smoother and more efficient. Cover the […]
Are you looking to boost your productivity and streamline your development process? Look no further than DevoxxGenie, the ultimate IntelliJ IDEA plugin designed to enhance your coding experience. Whether you’re a seasoned developer or just starting, this powerful tool offers a range of features to make your life easier. Key Features: Intelligent Code Suggestions: DevoxxGenie […]
The command line interface (CLI) has long been a staple tool for developers, but it hasn’t seen much innovation in recent years. Enter Warp Terminal, a modern, AI-powered terminal that aims to transform the way developers interact with their command line. Key Features of Warp Terminal 1. Modern UX – Edit easier, navigate faster. Feel […]
DBngin is a versatile database management tool that supports multiple database engines, including PostgreSQL, MySQL, and Redis. It offers a user-friendly interface, making it easy for developers to manage databases locally without the need for complex configurations. No Docker, no Virtual Machine. Key Features of DBngin: Multi-Engine Support: Manage different database engines from a single […]
Serverless Framework V4 has officially launched, bringing a host of new features and improvements without introducing any breaking changes. This latest version focuses on enhancing developer experience and expanding the framework’s capabilities. Key Highlights: 1. No Breaking Changes: V4 ensures a smooth transition from previous versions, allowing developers to adopt new features without disrupting existing […]
Encore.ts is a backend SDK designed to simplify the development of cloud backend applications using TypeScript. Move faster with purpose-built local dev tools and DevOps automation for AWS/GCP. Introduction to Encore.ts Encore.ts is a modern framework for web applications that offers efficient and flexible solutions for developers. Its main goal is to enable the fast […]
Ion, the new deployment engine for SST (Serverless Stack Toolkit). SST is a framework that simplifies building modern full-stack applications on your own infrastructure. Here’s what you need to know about Ion: What Is Ion?: on is an open-source engine designed for deploying SST applications. Unlike SST’s previous engine (which used CDK and CloudFormation), Ion […]
Laravel Reverb is a WebSocket server specifically designed for Laravel applications. It enables blazing-fast and scalable two-way communication between your server and client-side applications. Here are some key features: Real-Time Communication: Reverb allows you to establish real-time connections between clients and the server. Whether you’re building chat applications, live notifications, or collaborative tools, Reverb makes […]
Project IDX, Google’s latest IDE for developers. Built on the foundation of Google Cloud, IDX offers a cloud-based integrated development environment (IDE) that eliminates the need for extensive local setups. Everything’s in the cloud. With support for a broad range of frameworks, languages, and services, IDX streamlines your development workflow so you can build and […]
Storybook 8 introduces a range of exciting features and improvements, enhancing its capabilities as a tool for building and testing UI components. If you have a React project, this upgrade reduces your Storybook start time by up to 20%. For Webpack projects, Storybook 8 uses Speedy Web Compiler (SWC) as the default compiler for new […]
Micro frontends and monorepos are two different approaches to managing codebase of software application, and they serve different purposes: Micro frontends: Microfrontends extend the principles of microservices to the frontend world, allowing developers to break down a web application into smaller, more manageable pieces. Each piece, or „microfrontend,” is independently developed, tested, and deployed, typically […]
Next.js remains a top contender among full-stack frameworks. However, it might be time to move on from Version 14 because the Next.js 15 Release Candidate (RC) is now available! This new release brings a host of exciting features, and today, we’ll delve into four of the most notable ones. Let’s jump right in! 1. Caching […]
Version 18.0.0 is here and it has some great updates for Angular developers everywhere. 🎉 👉 Experimental support for zoneless change detection 👉 Angular.dev is now the new home for Angular developers 👉 Material 3, deferrable views, built-in control flow are now stable 👉 Server-side rendering improvements such as i18n hydration support 👉 More Additional […]
Understanding how to secure your JavaScript code can change that and help us to protect our applications and users. 1. Keep Your Dependencies Up-to-Date Failing to update libraries may leave your applications open to known security risks. Regular updates ensure you benefit from the latest fixes and enhancements. Use a Package Manager: npm, yarn or […]
React is a powerful library for building user interfaces, but as applications grow, developers may face performance challenges. Enter million.dev, a toolkit designed to enhance React’s rendering performance by introducing a novel virtual DOM implementation and an optimizing compiler. Let’s dive into how million.dev can make your React apps run faster and smoother. Understanding the […]
In the evolving landscape of software development, efficiency and scalability are paramount. This is where Nx hono monorepos come into play, offering a unified approach to managing multiple projects within a single repository. Nx, a build system with advanced CI capabilities, is revolutionizing the way developers work with monorepos, helping deliver high-quality products efficiently. What […]
Next.js is a popular React framework known for its capabilities in server-side rendering, static site generation, and creating efficient web applications. Docker, on the other hand, is a powerful tool that allows developers to containerize applications, ensuring that they run consistently across different environments. By combining these two, developers can enhance the scalability, reproducibility, and […]
Developing resilient and performant APIs is crucial in software development. Selecting the appropriate API technology is key to providing speedy, dependable, and secure services. When evaluating options, take into account project complexity, endpoint count, expected traffic, and team expertise. What is tRPC tRPC is an open source remote procedure call (RPC) framework that is fast, […]
In the realm of search engine optimization (SEO), the robots.txt file plays a pivotal role in guiding search engine crawlers through your website. As outlined in the Next.js documentation, this simple text file is crucial for managing crawler access and ensuring that only the content you want to be indexed is visible to search engines. […]
React component libraries are pre-built collections of reusable UI components. Choosing the right React component library is essential for the success. React UI libraries and component collections offer numerous advantages, making them a compelling choice for developers, such as: Navigation bars Forms Buttons Autocomplete Accordion Date Picker Slider Alerts Spinner … many more Here’s our […]