url
stringlengths
17
87
content
stringlengths
152
81.8k
https://react.dev
![logo by @sawaratsuki1004](/_next/image?url=%2Fimages%2Fuwu.png&w=640&q=75 "logo by @sawaratsuki1004") # React The library for web and native user interfaces [Learn React](https://react.dev/learn)[API Reference](https://react.dev/reference/react) ## Create user interfaces from components React lets you build user interfaces out of individual pieces called components. Create your own React components like `Thumbnail`, `LikeButton`, and `Video`. Then combine them into entire screens, pages, and apps. ### Video.js ``` function Video({ video }) { return ( <div> <Thumbnail video={video} /> <a href={video.url}> <h3>{video.title}</h3> <p>{video.description}</p> </a> <LikeButton video={video} /> </div> ); } ``` []()[**My video** \ Video description]() Whether you work on your own or with thousands of other developers, using React feels the same. It is designed to let you seamlessly combine components written by independent people, teams, and organizations. ## Write components with code and markup React components are JavaScript functions. Want to show some content conditionally? Use an `if` statement. Displaying a list? Try array `map()`. Learning React is learning programming. ### VideoList.js ``` function VideoList({ videos, emptyHeading }) { const count = videos.length; let heading = emptyHeading; if (count > 0) { const noun = count > 1 ? 'Videos' : 'Video'; heading = count + ' ' + noun; } return ( <section> <h2>{heading}</h2> {videos.map(video => <Video key={video.id} video={video} /> )} </section> ); } ``` ## 3 Videos []()[**First video** \ Video description]() []()[**Second video** \ Video description]() []()[**Third video** \ Video description]() This markup syntax is called JSX. It is a JavaScript syntax extension popularized by React. Putting JSX markup close to related rendering logic makes React components easy to create, maintain, and delete. ## Add interactivity wherever you need it React components receive data and return what should appear on the screen. You can pass them new data in response to an interaction, like when the user types into an input. React will then update the screen to match the new data. ### SearchableVideoList.js ``` import { useState } from 'react'; function SearchableVideoList({ videos }) { const [searchText, setSearchText] = useState(''); const foundVideos = filterVideos(videos, searchText); return ( <> <SearchInput value={searchText} onChange={newText => setSearchText(newText)} /> <VideoList videos={foundVideos} emptyHeading={`No matches for “${searchText}”`} /> </> ); } ``` example.com/videos.html # React Videos A brief history of React Search ## 5 Videos [](https://www.youtube.com/watch?v=8pDqJVdNa44)[**React: The Documentary** \ The origin story of React](https://www.youtube.com/watch?v=8pDqJVdNa44) [](https://www.youtube.com/watch?v=x7cQ3mrcKaY)[**Rethinking Best Practices** \ Pete Hunt (2013)](https://www.youtube.com/watch?v=x7cQ3mrcKaY) [](https://www.youtube.com/watch?v=KVZ-P-ZI6W4)[**Introducing React Native** \ Tom Occhino (2015)](https://www.youtube.com/watch?v=KVZ-P-ZI6W4) [](https://www.youtube.com/watch?v=V-QO-KO90iQ)[**Introducing React Hooks** \ Sophie Alpert and Dan Abramov (2018)](https://www.youtube.com/watch?v=V-QO-KO90iQ) [](https://www.youtube.com/watch?v=TQQPAU21ZUw)[**Introducing Server Components** \ Dan Abramov and Lauren Tan (2020)](https://www.youtube.com/watch?v=TQQPAU21ZUw) You don’t have to build your whole page in React. Add React to your existing HTML page, and render interactive React components anywhere on it. [Add React to your page](https://react.dev/learn/add-react-to-an-existing-project) ## Go full-stack with a framework React is a library. It lets you put components together, but it doesn’t prescribe how to do routing and data fetching. To build an entire app with React, we recommend a full-stack React framework like [Next.js](https://nextjs.org) or [Remix](https://remix.run). ### confs/\[slug].js ``` import { db } from './database.js'; import { Suspense } from 'react'; async function ConferencePage({ slug }) { const conf = await db.Confs.find({ slug }); return ( <ConferenceLayout conf={conf}> <Suspense fallback={<TalksLoading />}> <Talks confId={conf.id} /> </Suspense> </ConferenceLayout> ); } async function Talks({ confId }) { const talks = await db.Talks.findAll({ confId }); const videos = talks.map(talk => talk.video); return <SearchableVideoList videos={videos} />; } ``` example.com/confs/react-conf-2021 React Conf 2021React Conf 2019 ![](/images/home/conf2021/cover.svg) Search ## 19 Videos [![](/images/home/conf2021/andrew.jpg)![](/images/home/conf2021/lauren.jpg)![](/images/home/conf2021/juan.jpg)![](/images/home/conf2021/rick.jpg) \ React Conf](https://www.youtube.com/watch?v=FZ0cG47msEk&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=1) [**React 18 Keynote** \ The React Team](https://www.youtube.com/watch?v=FZ0cG47msEk&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=1) [![](/images/home/conf2021/shruti.jpg) \ React Conf](https://www.youtube.com/watch?v=ytudH8je5ko&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=2) [**React 18 for App Developers** \ Shruti Kapoor](https://www.youtube.com/watch?v=ytudH8je5ko&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=2) [![](/images/home/conf2021/shaundai.jpg) \ React Conf](https://www.youtube.com/watch?v=pj5N-Khihgc&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=3) [**Streaming Server Rendering with Suspense** \ Shaundai Person](https://www.youtube.com/watch?v=pj5N-Khihgc&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=3) [![](/images/home/conf2021/aakansha.jpg) \ React Conf](https://www.youtube.com/watch?v=qn7gRClrC9U&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=4) [**The First React Working Group** \ Aakansha Doshi](https://www.youtube.com/watch?v=qn7gRClrC9U&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=4) [![](/images/home/conf2021/brian.jpg) \ React Conf](https://www.youtube.com/watch?v=oxDfrke8rZg&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=5) [**React Developer Tooling** \ Brian Vaughn](https://www.youtube.com/watch?v=oxDfrke8rZg&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=5) [![](/images/home/conf2021/xuan.jpg) \ React Conf](https://www.youtube.com/watch?v=lGEMwh32soc&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=6) [**React without memo** \ Xuan Huang (黄玄)](https://www.youtube.com/watch?v=lGEMwh32soc&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=6) [![](/images/home/conf2021/rachel.jpg) \ React Conf](https://www.youtube.com/watch?v=mneDaMYOKP8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=7) [**React Docs Keynote** \ Rachel Nabors](https://www.youtube.com/watch?v=mneDaMYOKP8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=7) [![](/images/home/conf2021/debbie.jpg) \ React Conf](https://www.youtube.com/watch?v=-7odLW_hG7s&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=8) [**Things I Learnt from the New React Docs** \ Debbie O'Brien](https://www.youtube.com/watch?v=-7odLW_hG7s&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=8) [![](/images/home/conf2021/sarah.jpg) \ React Conf](https://www.youtube.com/watch?v=5X-WEQflCL0&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=9) [**Learning in the Browser** \ Sarah Rainsberger](https://www.youtube.com/watch?v=5X-WEQflCL0&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=9) [![](/images/home/conf2021/linton.jpg) \ React Conf](https://www.youtube.com/watch?v=7cPWmID5XAk&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=10) [**The ROI of Designing with React** \ Linton Ye](https://www.youtube.com/watch?v=7cPWmID5XAk&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=10) [![](/images/home/conf2021/delba.jpg) \ React Conf](https://www.youtube.com/watch?v=zL8cz2W0z34&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=11) [**Interactive Playgrounds with React** \ Delba de Oliveira](https://www.youtube.com/watch?v=zL8cz2W0z34&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=11) [![](/images/home/conf2021/robert.jpg) \ React Conf](https://www.youtube.com/watch?v=lhVGdErZuN4&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=12) [**Re-introducing Relay** \ Robert Balicki](https://www.youtube.com/watch?v=lhVGdErZuN4&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=12) [![](/images/home/conf2021/eric.jpg)![](/images/home/conf2021/steven.jpg) \ React Conf](https://www.youtube.com/watch?v=9L4FFrvwJwY&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=13) [**React Native Desktop** \ Eric Rozell and Steven Moyes](https://www.youtube.com/watch?v=9L4FFrvwJwY&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=13) [![](/images/home/conf2021/roman.jpg) \ React Conf](https://www.youtube.com/watch?v=NLj73vrc2I8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=14) [**On-device Machine Learning for React Native** \ Roman Rädle](https://www.youtube.com/watch?v=NLj73vrc2I8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=14) [![](/images/home/conf2021/daishi.jpg) \ React Conf](https://www.youtube.com/watch?v=oPfSC5bQPR8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=15) [**React 18 for External Store Libraries** \ Daishi Kato](https://www.youtube.com/watch?v=oPfSC5bQPR8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=15) [![](/images/home/conf2021/diego.jpg) \ React Conf](https://www.youtube.com/watch?v=dcm8fjBfro8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=16) [**Building Accessible Components with React 18** \ Diego Haz](https://www.youtube.com/watch?v=dcm8fjBfro8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=16) [![](/images/home/conf2021/tafu.jpg) \ React Conf](https://www.youtube.com/watch?v=S4a0QlsH0pU&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=17) [**Accessible Japanese Form Components with React** \ Tafu Nakazaki](https://www.youtube.com/watch?v=S4a0QlsH0pU&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=17) [![](/images/home/conf2021/lyle.jpg) \ React Conf](https://www.youtube.com/watch?v=b3l4WxipFsE&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=18) [**UI Tools for Artists** \ Lyle Troxell](https://www.youtube.com/watch?v=b3l4WxipFsE&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=18) [![](/images/home/conf2021/helen.jpg) \ React Conf](https://www.youtube.com/watch?v=HS6vIYkSNks&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=19) [**Hydrogen + React 18** \ Helen Lin](https://www.youtube.com/watch?v=HS6vIYkSNks&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=19) React is also an architecture. Frameworks that implement it let you fetch data in asynchronous components that run on the server or even during the build. Read data from a file or a database, and pass it down to your interactive components. [Get started with a framework](https://react.dev/learn/start-a-new-react-project) ## Use the best from every platform People love web and native apps for different reasons. React lets you build both web apps and native apps using the same skills. It leans upon each platform’s unique strengths to let your interfaces feel just right on every platform. example.com #### Stay true to the web People expect web app pages to load fast. On the server, React lets you start streaming HTML while you’re still fetching data, progressively filling in the remaining content before any JavaScript code loads. On the client, React can use standard web APIs to keep your UI responsive even in the middle of rendering. 12:23 PM #### Go truly native People expect native apps to look and feel like their platform. [React Native](https://reactnative.dev) and [Expo](https://github.com/expo/expo) let you build apps in React for Android, iOS, and more. They look and feel native because their UIs *are* truly native. It’s not a web view—your React components render real Android and iOS views provided by the platform. With React, you can be a web *and* a native developer. Your team can ship to many platforms without sacrificing the user experience. Your organization can bridge the platform silos, and form teams that own entire features end-to-end. [Build for native platforms](https://reactnative.dev/) ## Upgrade when the future is ready React approaches changes with care. Every React commit is tested on business-critical surfaces with over a billion users. Over 100,000 React components at Meta help validate every migration strategy. The React team is always researching how to improve React. Some research takes years to pay off. React has a high bar for taking a research idea into production. Only proven approaches become a part of React. [Read more React news](https://react.dev/blog) Latest React News [**React 19** \ December 05, 2024](https://react.dev/blog/2024/12/05/react-19) [**React Compiler Beta Release and Roadmap** \ October 21, 2024](https://react.dev/blog/2024/10/21/react-compiler-beta-release) [**React Conf 2024 Recap** \ May 22, 2024](https://react.dev/blog/2024/05/22/react-conf-2024-recap) [**React 19 RC** \ April 25, 2024](https://react.dev/blog/2024/04/25/react-19) [Read more React news](https://react.dev/blog) ## Join a community of millions You’re not alone. Two million developers from all over the world visit the React docs every month. React is something that people and teams can agree on. ![People singing karaoke at React Conf](/images/home/community/react_conf_fun.webp) ![Sunil Pai speaking at React India](/images/home/community/react_india_sunil.webp) ![A hallway conversation between two people at React Conf](/images/home/community/react_conf_hallway.webp) ![A hallway conversation at React India](/images/home/community/react_india_hallway.webp) ![Elizabet Oliveira speaking at React Conf](/images/home/community/react_conf_elizabet.webp) ![People taking a group selfie at React India](/images/home/community/react_india_selfie.webp) ![Nat Alison speaking at React Conf](/images/home/community/react_conf_nat.webp) ![Organizers greeting attendees at React India](/images/home/community/react_india_team.webp) ![People singing karaoke at React Conf](/images/home/community/react_conf_fun.webp) ![Sunil Pai speaking at React India](/images/home/community/react_india_sunil.webp) ![A hallway conversation between two people at React Conf](/images/home/community/react_conf_hallway.webp) ![A hallway conversation at React India](/images/home/community/react_india_hallway.webp) ![Elizabet Oliveira speaking at React Conf](/images/home/community/react_conf_elizabet.webp) ![People taking a group selfie at React India](/images/home/community/react_india_selfie.webp) ![Nat Alison speaking at React Conf](/images/home/community/react_conf_nat.webp) ![Organizers greeting attendees at React India](/images/home/community/react_india_team.webp) This is why React is more than a library, an architecture, or even an ecosystem. React is a community. It’s a place where you can ask for help, find opportunities, and meet new friends. You will meet both developers and designers, beginners and experts, researchers and artists, teachers and students. Our backgrounds may be very different, but React lets us all create user interfaces together. ![logo by @sawaratsuki1004](/images/uwu.png "logo by @sawaratsuki1004") ## Welcome to the React community [Get Started](https://react.dev/learn)
https://react.dev/community
[Community](https://react.dev/community) # React Community[Link for this heading]() React has a community of millions of developers. On this page we’ve listed some React-related communities that you can be a part of; see the other pages in this section for additional online and in-person learning materials. ## Code of Conduct[Link for Code of Conduct]() Before participating in React’s communities, [please read our Code of Conduct.](https://github.com/facebook/react/blob/main/CODE_OF_CONDUCT.md) We have adopted the [Contributor Covenant](https://www.contributor-covenant.org/) and we expect that all community members adhere to the guidelines within. ## Stack Overflow[Link for Stack Overflow]() Stack Overflow is a popular forum to ask code-level questions or if you’re stuck with a specific error. Read through the [existing questions](https://stackoverflow.com/questions/tagged/reactjs) tagged with **reactjs** or [ask your own](https://stackoverflow.com/questions/ask?tags=reactjs)! ## Popular Discussion Forums[Link for Popular Discussion Forums]() There are many online forums which are a great place for discussion about best practices and application architecture as well as the future of React. If you have an answerable code-level question, Stack Overflow is usually a better fit. Each community consists of many thousands of React users. - [DEV’s React community](https://dev.to/t/react) - [Hashnode’s React community](https://hashnode.com/n/reactjs) - [Reactiflux online chat](https://discord.gg/reactiflux) - [Reddit’s React community](https://www.reddit.com/r/reactjs/) ## News[Link for News]() For the latest news about React, [follow **@reactjs** on Twitter](https://twitter.com/reactjs) and the [official React blog](https://react.dev/blog) on this website. [NextReact Conferences](https://react.dev/community/conferences)
https://react.dev/reference/react
[API Reference](https://react.dev/reference/react) # React Reference Overview[Link for this heading]() This section provides detailed reference documentation for working with React. For an introduction to React, please visit the [Learn](https://react.dev/learn) section. The React reference documentation is broken down into functional subsections: ## React[Link for React]() Programmatic React features: - [Hooks](https://react.dev/reference/react/hooks) - Use different React features from your components. - [Components](https://react.dev/reference/react/components) - Built-in components that you can use in your JSX. - [APIs](https://react.dev/reference/react/apis) - APIs that are useful for defining components. - [Directives](https://react.dev/reference/rsc/directives) - Provide instructions to bundlers compatible with React Server Components. ## React DOM[Link for React DOM]() React-dom contains features that are only supported for web applications (which run in the browser DOM environment). This section is broken into the following: - [Hooks](https://react.dev/reference/react-dom/hooks) - Hooks for web applications which run in the browser DOM environment. - [Components](https://react.dev/reference/react-dom/components) - React supports all of the browser built-in HTML and SVG components. - [APIs](https://react.dev/reference/react-dom) - The `react-dom` package contains methods supported only in web applications. - [Client APIs](https://react.dev/reference/react-dom/client) - The `react-dom/client` APIs let you render React components on the client (in the browser). - [Server APIs](https://react.dev/reference/react-dom/server) - The `react-dom/server` APIs let you render React components to HTML on the server. ## Rules of React[Link for Rules of React]() React has idioms — or rules — for how to express patterns in a way that is easy to understand and yields high-quality applications: - [Components and Hooks must be pure](https://react.dev/reference/rules/components-and-hooks-must-be-pure) – Purity makes your code easier to understand, debug, and allows React to automatically optimize your components and hooks correctly. - [React calls Components and Hooks](https://react.dev/reference/rules/react-calls-components-and-hooks) – React is responsible for rendering components and hooks when necessary to optimize the user experience. - [Rules of Hooks](https://react.dev/reference/rules/rules-of-hooks) – Hooks are defined using JavaScript functions, but they represent a special type of reusable UI logic with restrictions on where they can be called. ## Legacy APIs[Link for Legacy APIs]() - [Legacy APIs](https://react.dev/reference/react/legacy) - Exported from the `react` package, but not recommended for use in newly written code. [NextHooks](https://react.dev/reference/react/hooks)
https://react.dev/blog
[Blog](https://react.dev/blog) # React Blog[Link for this heading]() This blog is the official source for the updates from the React team. Anything important, including release notes or deprecation notices, will be posted here first. You can also follow the [@reactjs](https://twitter.com/reactjs) account on Twitter, but you won’t miss anything essential if you only read this blog. [**React v19** \ December 5, 2024 \ In the React 19 Upgrade Guide, we shared step-by-step instructions for upgrading your app to React 19. In this post, we’ll give an overview of the new features in React 19, and how you can adopt them … \ Read more](https://react.dev/blog/2024/12/05/react-19) [**React Compiler Beta Release** \ October 21, 2024 \ We announced an experimental release of React Compiler at React Conf 2024. We’ve made a lot of progress since then, and in this post we want to share what’s next for React Compiler … \ Read more](https://react.dev/blog/2024/10/21/react-compiler-beta-release) [**React Conf 2024 Recap** \ May 22, 2024 \ Last week we hosted React Conf 2024, a two-day conference in Henderson, Nevada where 700+ attendees gathered in-person to discuss the latest in UI engineering. This was our first in-person conference since 2019, and we were thrilled to be able to bring the community together again … \ Read more](https://react.dev/blog/2024/05/22/react-conf-2024-recap) [**React 19 Upgrade Guide** \ April 25, 2024 \ The improvements added to React 19 require some breaking changes, but we’ve worked to make the upgrade as smooth as possible, and we don’t expect the changes to impact most apps. In this post, we will guide you through the steps for upgrading libraries to React 19 … \ Read more](https://react.dev/blog/2024/04/25/react-19-upgrade-guide) [**React Labs: What We've Been Working On – February 2024** \ February 15, 2024 \ In React Labs posts, we write about projects in active research and development. Since our last update, we’ve made significant progress on React Compiler, new features, and React 19, and we’d like to share what we learned. \ Read more](https://react.dev/blog/2024/02/15/react-labs-what-we-have-been-working-on-february-2024) [**React Canaries: Incremental Feature Rollout Outside Meta** \ May 3, 2023 \ Traditionally, new React features used to only be available at Meta first, and land in the open source releases later. We’d like to offer the React community an option to adopt individual new features as soon as their design is close to final—similar to how Meta uses React internally. We are introducing a new officially supported Canary release channel. It lets curated setups like frameworks decouple adoption of individual React features from the React release schedule. \ Read more](https://react.dev/blog/2023/05/03/react-canaries) [**React Labs: What We've Been Working On – March 2023** \ March 22, 2023 \ In React Labs posts, we write about projects in active research and development. Since our last update, we’ve made significant progress on React Server Components, Asset Loading, Optimizing Compiler, Offscreen Rendering, and Transition Tracing, and we’d like to share what we learned. \ Read more](https://react.dev/blog/2023/03/22/react-labs-what-we-have-been-working-on-march-2023) [**Introducing react.dev** \ March 16, 2023 \ Today we are thrilled to launch react.dev, the new home for React and its documentation. In this post, we would like to give you a tour of the new site. \ Read more](https://react.dev/blog/2023/03/16/introducing-react-dev) [**React Labs: What We've Been Working On – June 2022** \ June 15, 2022 \ React 18 was years in the making, and with it brought valuable lessons for the React team. Its release was the result of many years of research and exploring many paths. Some of those paths were successful; many more were dead-ends that led to new insights. One lesson we’ve learned is that it’s frustrating for the community to wait for new features without having insight into these paths that we’re exploring… \ Read more](https://react.dev/blog/2022/06/15/react-labs-what-we-have-been-working-on-june-2022) [**React v18.0** \ March 29, 2022 \ React 18 is now available on npm! In our last post, we shared step-by-step instructions for upgrading your app to React 18. In this post, we’ll give an overview of what’s new in React 18, and what it means for the future… \ Read more](https://react.dev/blog/2022/03/29/react-v18) [**How to Upgrade to React 18** \ March 8, 2022 \ As we shared in the release post, React 18 introduces features powered by our new concurrent renderer, with a gradual adoption strategy for existing applications. In this post, we will guide you through the steps for upgrading to React 18… \ Read more](https://react.dev/blog/2022/03/08/react-18-upgrade-guide) [**React Conf 2021 Recap** \ December 17, 2021 \ Last week we hosted our 6th React Conf. In previous years, we’ve used the React Conf stage to deliver industry changing announcements such as React Native and React Hooks. This year, we shared our multi-platform vision for React, starting with the release of React 18 and gradual adoption of concurrent features… \ Read more](https://react.dev/blog/2021/12/17/react-conf-2021-recap) [**The Plan for React 18** \ June 8, 2021 \ The React team is excited to share a few updates: \ We’ve started work on the React 18 release, which will be our next major version. We’ve created a Working Group to prepare the community for gradual adoption of new features in React 18. We’ve published a React 18 Alpha so that library authors can try it and provide feedback… \ Read more](https://react.dev/blog/2021/06/08/the-plan-for-react-18) [**Introducing Zero-Bundle-Size React Server Components** \ December 21, 2020 \ 2020 has been a long year. As it comes to an end we wanted to share a special Holiday Update on our research into zero-bundle-size React Server Components. To introduce React Server Components, we have prepared a talk and a demo. If you want, you can check them out during the holidays, or later when work picks back up in the new year… \ Read more](https://react.dev/blog/2020/12/21/data-fetching-with-react-server-components) * * * ### All release notes[Link for All release notes]() Not every React release deserves its own blog post, but you can find a detailed changelog for every release in the [`CHANGELOG.md`](https://github.com/facebook/react/blob/main/CHANGELOG.md) file in the React repository, as well as on the [Releases](https://github.com/facebook/react/releases) page. * * * ### Older posts[Link for Older posts]() See the [older posts.](https://reactjs.org/blog/all.html)
https://react.dev/versions
[React Docs](https://react.dev/) # React Versions[Link for this heading]() The React docs at [react.dev](https://react.dev) provide documentation for the latest version of React. We aim to keep the docs updated within major versions, and do not publish versions for each minor or patch version. When a new major is released, we archive the docs for the previous version as `x.react.dev`. See our [versioning policy](https://react.dev/community/versioning-policy) for more info. You can find an archive of previous major versions below. ## Latest version: 19.0[Link for Latest version: 19.0]() - [react.dev](https://react.dev) ## Previous versions[Link for Previous versions]() - [18.react.dev](https://18.react.dev) - [17.react.dev](https://17.react.dev) - [16.react.dev](https://16.react.dev) - [15.react.dev](https://15.react.dev) ### Note #### Legacy Docs[Link for Legacy Docs]() In 2023, we [launched our new docs](https://react.dev/blog/2023/03/16/introducing-react-dev) for React 18 as [react.dev](https://react.dev). The legacy React 18 docs are available at [legacy.reactjs.org](https://legacy.reactjs.org). Versions 17 and below are hosted on legacy sites. For versions older than React 15, see [15.react.dev](https://15.react.dev). ## Changelog[Link for Changelog]() ### React 19[Link for React 19]() **Blog Posts** - [React v19](https://react.dev/blog/2024/12/05/react-19) - [React 19 Upgrade Guide](https://react.dev/blog/2024/04/25/react-19-upgrade-guide) - [React Compiler Beta Release](https://react.dev/blog/2024/10/21/react-compiler-beta-release) **Talks** - [React 19 Keynote](https://www.youtube.com/watch?v=lyEKhv8-3n0) - [A Roadmap to React 19](https://www.youtube.com/watch?v=R0B2HsSM78s) - [What’s new in React 19](https://www.youtube.com/watch?v=AJOGzVygGcY) - [React for Two Computers](https://www.youtube.com/watch?v=ozI4V_29fj4) - [React Compiler Deep Dive](https://www.youtube.com/watch?v=uA_PVyZP7AI) - [React Compiler Case Studies](https://www.youtube.com/watch?v=lvhPq5chokM) - [React 19 Deep Dive: Coordinating HTML](https://www.youtube.com/watch?v=IBBN-s77YSI) **Releases** - [v19.0.0 (December, 2024)](https://github.com/facebook/react/blob/main/CHANGELOG.md) ### React 18[Link for React 18]() **Blog Posts** - [React v18.0](https://react.dev/blog/2022/03/29/react-v18) - [How to Upgrade to React 18](https://react.dev/blog/2022/03/08/react-18-upgrade-guide) - [The Plan for React 18](https://react.dev/blog/2021/06/08/the-plan-for-react-18) **Talks** - [React 18 Keynote](https://www.youtube.com/watch?v=FZ0cG47msEk) - [React 18 for app developers](https://www.youtube.com/watch?v=ytudH8je5ko) - [Streaming Server Rendering with Suspense](https://www.youtube.com/watch?v=pj5N-Khihgc) - [React without memo](https://www.youtube.com/watch?v=lGEMwh32soc) - [React Docs Keynote](https://www.youtube.com/watch?v=mneDaMYOKP8) - [React Developer Tooling](https://www.youtube.com/watch?v=oxDfrke8rZg) - [The first React Working Group](https://www.youtube.com/watch?v=qn7gRClrC9U) - [React 18 for External Store Libraries](https://www.youtube.com/watch?v=oPfSC5bQPR8) **Releases** - [v18.3.1 (April, 2024)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v18.3.0 (April, 2024)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v18.2.0 (June, 2022)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v18.1.0 (April, 2022)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v18.0.0 (March 2022)](https://github.com/facebook/react/blob/main/CHANGELOG.md) ### React 17[Link for React 17]() **Blog Posts** - [React v17.0](https://legacy.reactjs.org/blog/2020/10/20/react-v17.html) - [Introducing the New JSX Transform](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) - [React v17.0 Release Candidate: No New Features](https://legacy.reactjs.org/blog/2020/08/10/react-v17-rc.html) **Releases** - [v17.0.2 (March 2021)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v17.0.1 (October 2020)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v17.0.0 (October 2020)](https://github.com/facebook/react/blob/main/CHANGELOG.md) ### React 16[Link for React 16]() **Blog Posts** - [React v16.0](https://legacy.reactjs.org/blog/2017/09/26/react-v16.0.html) - [DOM Attributes in React 16](https://legacy.reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html) - [Error Handling in React 16](https://legacy.reactjs.org/blog/2017/07/26/error-handling-in-react-16.html) - [React v16.2.0: Improved Support for Fragments](https://legacy.reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html) - [React v16.4.0: Pointer Events](https://legacy.reactjs.org/blog/2018/05/23/react-v-16-4.html) - [React v16.4.2: Server-side vulnerability fix](https://legacy.reactjs.org/blog/2018/08/01/react-v-16-4-2.html) - [React v16.6.0: lazy, memo and contextType](https://legacy.reactjs.org/blog/2018/10/23/react-v-16-6.html) - [React v16.7: No, This Is Not the One With Hooks](https://legacy.reactjs.org/blog/2018/12/19/react-v-16-7.html) - [React v16.8: The One With Hooks](https://legacy.reactjs.org/blog/2019/02/06/react-v16.8.0.html) - [React v16.9.0 and the Roadmap Update](https://legacy.reactjs.org/blog/2019/08/08/react-v16.9.0.html) - [React v16.13.0](https://legacy.reactjs.org/blog/2020/02/26/react-v16.13.0.html) **Releases** - [v16.14.0 (October 2020)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.13.1 (March 2020)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.13.0 (February 2020)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.12.0 (November 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.11.0 (October 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.10.2 (October 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.10.1 (September 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.10.0 (September 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.9.0 (August 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.8.6 (March 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.8.5 (March 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.8.4 (March 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.8.3 (February 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.8.2 (February 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.8.1 (February 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.8.0 (February 2019)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.7.0 (December 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.6.3 (November 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.6.2 (November 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.6.1 (November 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.6.0 (October 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.5.2 (September 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.5.1 (September 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.5.0 (September 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.4.2 (August 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.4.1 (June 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.4.0 (May 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.3.3 (August 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.3.2 (April 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.3.1 (April 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.3.0 (March 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.2.1 (August 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.2.0 (November 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.1.2 (August 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.1.1 (November 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.1.0 (November 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.0.1 (August 2018)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v16.0 (September 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) ### React 15[Link for React 15]() **Blog Posts** - [React v15.0](https://legacy.reactjs.org/blog/2016/04/07/react-v15.html) - [React v15.0 Release Candidate 2](https://legacy.reactjs.org/blog/2016/03/16/react-v15-rc2.html) - [React v15.0 Release Candidate](https://legacy.reactjs.org/blog/2016/03/07/react-v15-rc1.html) - [New Versioning Scheme](https://legacy.reactjs.org/blog/2016/02/19/new-versioning-scheme.html) - [Discontinuing IE 8 Support in React DOM](https://legacy.reactjs.org/blog/2016/01/12/discontinuing-ie8-support.html) - [Introducing React’s Error Code System](https://legacy.reactjs.org/blog/2016/07/11/introducing-reacts-error-code-system.html) - [React v15.0.1](https://legacy.reactjs.org/blog/2016/04/08/react-v15.0.1.html) - [React v15.4.0](https://legacy.reactjs.org/blog/2016/11/16/react-v15.4.0.html) - [React v15.5.0](https://legacy.reactjs.org/blog/2017/04/07/react-v15.5.0.html) - [React v15.6.0](https://legacy.reactjs.org/blog/2017/06/13/react-v15.6.0.html) - [React v15.6.2](https://legacy.reactjs.org/blog/2017/09/25/react-v15.6.2.html) **Releases** - [v15.7.0 (October 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.6.2 (September 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.6.1 (June 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.6.0 (June 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.5.4 (April 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.5.3 (April 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.5.2 (April 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.5.1 (April 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.5.0 (April 2017)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.4.2 (January 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.4.1 (November 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.4.0 (November 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.3.2 (September 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.3.1 (August 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.3.0 (July 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.2.1 (July 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.2.0 (July 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.1.0 (May 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.0.2 (April 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.0.1 (April 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v15.0.0 (April 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) ### React 0.14[Link for React 0.14]() **Blog Posts** - [React v0.14](https://legacy.reactjs.org/blog/2015/10/07/react-v0.14.html) - [React v0.14 Release Candidate](https://legacy.reactjs.org/blog/2015/09/10/react-v0.14-rc1.html) - [React v0.14 Beta 1](https://legacy.reactjs.org/blog/2015/07/03/react-v0.14-beta-1.html) - [New React Developer Tools](https://legacy.reactjs.org/blog/2015/09/02/new-react-developer-tools.html) - [New React Devtools Beta](https://legacy.reactjs.org/blog/2015/08/03/new-react-devtools-beta.html) - [React v0.14.1](https://legacy.reactjs.org/blog/2015/10/28/react-v0.14.1.html) - [React v0.14.2](https://legacy.reactjs.org/blog/2015/11/02/react-v0.14.2.html) - [React v0.14.3](https://legacy.reactjs.org/blog/2015/11/18/react-v0.14.3.html) - [React v0.14.4](https://legacy.reactjs.org/blog/2015/12/29/react-v0.14.4.html) - [React v0.14.8](https://legacy.reactjs.org/blog/2016/03/29/react-v0.14.8.html) **Releases** - [v0.14.10 (October 2020)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.14.8 (March 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.14.7 (January 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.14.6 (January 2016)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.14.5 (December 2015)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.14.4 (December 2015)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.14.3 (November 2015)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.14.2 (November 2015)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.14.1 (October 2015)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.14.0 (October 2015)](https://github.com/facebook/react/blob/main/CHANGELOG.md) ### React 0.13[Link for React 0.13]() **Blog Posts** - [React Native v0.4](https://legacy.reactjs.org/blog/2015/04/17/react-native-v0.4.html) - [React v0.13](https://legacy.reactjs.org/blog/2015/03/10/react-v0.13.html) - [React v0.13 RC2](https://legacy.reactjs.org/blog/2015/03/03/react-v0.13-rc2.html) - [React v0.13 RC](https://legacy.reactjs.org/blog/2015/02/24/react-v0.13-rc1.html) - [React v0.13.0 Beta 1](https://legacy.reactjs.org/blog/2015/01/27/react-v0.13.0-beta-1.html) - [Streamlining React Elements](https://legacy.reactjs.org/blog/2015/02/24/streamlining-react-elements.html) - [Introducing Relay and GraphQL](https://legacy.reactjs.org/blog/2015/02/20/introducing-relay-and-graphql.html) - [Introducing React Native](https://legacy.reactjs.org/blog/2015/03/26/introducing-react-native.html) - [React v0.13.1](https://legacy.reactjs.org/blog/2015/03/16/react-v0.13.1.html) - [React v0.13.2](https://legacy.reactjs.org/blog/2015/04/18/react-v0.13.2.html) - [React v0.13.3](https://legacy.reactjs.org/blog/2015/05/08/react-v0.13.3.html) **Releases** - [v0.13.3 (May 2015)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.13.2 (April 2015)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.13.1 (March 2015)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.13.0 (March 2015)](https://github.com/facebook/react/blob/main/CHANGELOG.md) ### React 0.12[Link for React 0.12]() **Blog Posts** - [React v0.12](https://legacy.reactjs.org/blog/2014/10/28/react-v0.12.html) - [React v0.12 RC](https://legacy.reactjs.org/blog/2014/10/16/react-v0.12-rc1.html) - [Introducing React Elements](https://legacy.reactjs.org/blog/2014/10/14/introducing-react-elements.html) - [React v0.12.2](https://legacy.reactjs.org/blog/2014/12/18/react-v0.12.2.html) **Releases** - [v0.12.2 (December 2014)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.12.1 (November 2014)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.12.0 (October 2014)](https://github.com/facebook/react/blob/main/CHANGELOG.md) ### React 0.11[Link for React 0.11]() **Blog Posts** - [React v0.11](https://legacy.reactjs.org/blog/2014/07/17/react-v0.11.html) - [React v0.11 RC](https://legacy.reactjs.org/blog/2014/07/13/react-v0.11-rc1.html) - [One Year of Open-Source React](https://legacy.reactjs.org/blog/2014/05/29/one-year-of-open-source-react.html) - [The Road to 1.0](https://legacy.reactjs.org/blog/2014/03/28/the-road-to-1.0.html) - [React v0.11.1](https://legacy.reactjs.org/blog/2014/07/25/react-v0.11.1.html) - [React v0.11.2](https://legacy.reactjs.org/blog/2014/09/16/react-v0.11.2.html) - [Introducing the JSX Specificaion](https://legacy.reactjs.org/blog/2014/09/03/introducing-the-jsx-specification.html) **Releases** - [v0.11.2 (September 2014)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.11.1 (July 2014)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.11.0 (July 2014)](https://github.com/facebook/react/blob/main/CHANGELOG.md) ### React 0.10 and below[Link for React 0.10 and below]() **Blog Posts** - [React v0.10](https://legacy.reactjs.org/blog/2014/03/21/react-v0.10.html) - [React v0.10 RC](https://legacy.reactjs.org/blog/2014/03/19/react-v0.10-rc1.html) - [React v0.9](https://legacy.reactjs.org/blog/2014/02/20/react-v0.9.html) - [React v0.9 RC](https://legacy.reactjs.org/blog/2014/02/16/react-v0.9-rc1.html) - [React Chrome Developer Tools](https://legacy.reactjs.org/blog/2014/01/02/react-chrome-developer-tools.html) - [React v0.8](https://legacy.reactjs.org/blog/2013/12/19/react-v0.8.0.html) - [React v0.5.2, v0.4.2](https://legacy.reactjs.org/blog/2013/12/18/react-v0.5.2-v0.4.2.html) - [React v0.5.1](https://legacy.reactjs.org/blog/2013/10/29/react-v0-5-1.html) - [React v0.5](https://legacy.reactjs.org/blog/2013/10/16/react-v0.5.0.html) - [React v0.4.1](https://legacy.reactjs.org/blog/2013/07/26/react-v0-4-1.html) - [React v0.4.0](https://legacy.reactjs.org/blog/2013/07/17/react-v0-4-0.html) - [New in React v0.4: Prop Validation and Default Values](https://legacy.reactjs.org/blog/2013/07/11/react-v0-4-prop-validation-and-default-values.html) - [New in React v0.4: Autobind by Default](https://legacy.reactjs.org/blog/2013/07/02/react-v0-4-autobind-by-default.html) - [React v0.3.3](https://legacy.reactjs.org/blog/2013/07/02/react-v0-4-autobind-by-default.html) **Releases** - [v0.10.0 (March 2014)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.9.0 (February 2014)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.8.0 (December 2013)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.5.2 (December 2013)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.5.1 (October 2013)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.5.0 (October 2013)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.4.1 (July 2013)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.4.0 (July 2013)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.3.3 (June 2013)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.3.2 (May 2013)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.3.1 (May 2013)](https://github.com/facebook/react/blob/main/CHANGELOG.md) - [v0.3.0 (May 2013)](https://github.com/facebook/react/blob/main/CHANGELOG.md) ### Initial Commit[Link for Initial Commit]() React was open-sourced on May 29, 2013. The initial commit is: [`75897c`: Initial public release](https://github.com/facebook/react/commit/75897c2dcd1dd3a6ca46284dd37e13d22b4b16b4) See the first blog post: [Why did we build React?](https://legacy.reactjs.org/blog/2013/06/05/why-react.html) React was open sourced at Facebook Seattle in 2013:
https://react.dev/community/translations
[Community](https://react.dev/community) # Translations[Link for this heading]() React docs are translated by the global community into many languages all over the world. ## Source site[Link for Source site]() All translations are provided from the canonical source docs: - [English](https://react.dev/) — [Contribute](https://github.com/reactjs/react.dev/) ## Full translations[Link for Full translations]() - [French (Français)](https://fr.react.dev/) — [Contribute](https://github.com/reactjs/fr.react.dev) - [Japanese (日本語)](https://ja.react.dev/) — [Contribute](https://github.com/reactjs/ja.react.dev) - [Korean (한국어)](https://ko.react.dev/) — [Contribute](https://github.com/reactjs/ko.react.dev) - [Simplified Chinese (简体中文)](https://zh-hans.react.dev/) — [Contribute](https://github.com/reactjs/zh-hans.react.dev) - [Spanish (Español)](https://es.react.dev/) — [Contribute](https://github.com/reactjs/es.react.dev) - [Turkish (Türkçe)](https://tr.react.dev/) — [Contribute](https://github.com/reactjs/tr.react.dev) ## In-progress translations[Link for In-progress translations]() For the progress of each translation, see: [Is React Translated Yet?](https://translations.react.dev/) - [Arabic (العربية)](https://ar.react.dev/) — [Contribute](https://github.com/reactjs/ar.react.dev) - [Azerbaijani (Azərbaycanca)](https://az.react.dev/) — [Contribute](https://github.com/reactjs/az.react.dev) - [Belarusian (Беларуская)](https://be.react.dev/) — [Contribute](https://github.com/reactjs/be.react.dev) - [Bengali (বাংলা)](https://bn.react.dev/) — [Contribute](https://github.com/reactjs/bn.react.dev) - [Czech (Čeština)](https://cs.react.dev/) — [Contribute](https://github.com/reactjs/cs.react.dev) - [Finnish (Suomi)](https://fi.react.dev/) — [Contribute](https://github.com/reactjs/fi.react.dev) - [German (Deutsch)](https://de.react.dev/) — [Contribute](https://github.com/reactjs/de.react.dev) - [Gujarati (ગુજરાતી)](https://gu.react.dev/) — [Contribute](https://github.com/reactjs/gu.react.dev) - [Hebrew (עברית)](https://he.react.dev/) — [Contribute](https://github.com/reactjs/he.react.dev) - [Hindi (हिन्दी)](https://hi.react.dev/) — [Contribute](https://github.com/reactjs/hi.react.dev) - [Hungarian (magyar)](https://hu.react.dev/) — [Contribute](https://github.com/reactjs/hu.react.dev) - [Icelandic (Íslenska)](https://is.react.dev/) — [Contribute](https://github.com/reactjs/is.react.dev) - [Indonesian (Bahasa Indonesia)](https://id.react.dev/) — [Contribute](https://github.com/reactjs/id.react.dev) - [Italian (Italiano)](https://it.react.dev/) — [Contribute](https://github.com/reactjs/it.react.dev) - [Kazakh (Қазақша)](https://kk.react.dev/) — [Contribute](https://github.com/reactjs/kk.react.dev) - [Lao (ພາສາລາວ)](https://lo.react.dev/) — [Contribute](https://github.com/reactjs/lo.react.dev) - [Macedonian (Македонски)](https://mk.react.dev/) — [Contribute](https://github.com/reactjs/mk.react.dev) - [Malayalam (മലയാളം)](https://ml.react.dev/) — [Contribute](https://github.com/reactjs/ml.react.dev) - [Mongolian (Монгол хэл)](https://mn.react.dev/) — [Contribute](https://github.com/reactjs/mn.react.dev) - [Persian (فارسی)](https://fa.react.dev/) — [Contribute](https://github.com/reactjs/fa.react.dev) - [Polish (Polski)](https://pl.react.dev/) — [Contribute](https://github.com/reactjs/pl.react.dev) - [Portuguese (Brazil) (Português do Brasil)](https://pt-br.react.dev/) — [Contribute](https://github.com/reactjs/pt-br.react.dev) - [Russian (Русский)](https://ru.react.dev/) — [Contribute](https://github.com/reactjs/ru.react.dev) - [Serbian (Srpski)](https://sr.react.dev/) — [Contribute](https://github.com/reactjs/sr.react.dev) - [Sinhala (සිංහල)](https://si.react.dev/) — [Contribute](https://github.com/reactjs/si.react.dev) - [Swahili (Kiswahili)](https://sw.react.dev/) — [Contribute](https://github.com/reactjs/sw.react.dev) - [Tamil (தமிழ்)](https://ta.react.dev/) — [Contribute](https://github.com/reactjs/ta.react.dev) - [Telugu (తెలుగు)](https://te.react.dev/) — [Contribute](https://github.com/reactjs/te.react.dev) - [Traditional Chinese (繁體中文)](https://zh-hant.react.dev/) — [Contribute](https://github.com/reactjs/zh-hant.react.dev) - [Ukrainian (Українська)](https://uk.react.dev/) — [Contribute](https://github.com/reactjs/uk.react.dev) - [Urdu (اردو)](https://ur.react.dev/) — [Contribute](https://github.com/reactjs/ur.react.dev) - [Vietnamese (Tiếng Việt)](https://vi.react.dev/) — [Contribute](https://github.com/reactjs/vi.react.dev) ## How to contribute[Link for How to contribute]() You can contribute to the translation efforts! The community conducts the translation work for the React docs on each language-specific fork of react.dev. Typical translation work involves directly translating a Markdown file and creating a pull request. Click the “contribute” link above to the GitHub repository for your language, and follow the instructions there to help with the translation effort. If you want to start a new translation for your language, visit: [translations.react.dev](https://github.com/reactjs/translations.react.dev) [PreviousDocs Contributors](https://react.dev/community/docs-contributors) [NextAcknowledgements](https://react.dev/community/acknowledgements)
https://react.dev/learn
[Learn React](https://react.dev/learn) # Quick Start[Link for this heading]() Welcome to the React documentation! This page will give you an introduction to 80% of the React concepts that you will use on a daily basis. ### You will learn - How to create and nest components - How to add markup and styles - How to display data - How to render conditions and lists - How to respond to events and update the screen - How to share data between components ## Creating and nesting components[Link for Creating and nesting components]() React apps are made out of *components*. A component is a piece of the UI (user interface) that has its own logic and appearance. A component can be as small as a button, or as large as an entire page. React components are JavaScript functions that return markup: ``` function MyButton() { return ( <button>I'm a button</button> ); } ``` Now that you’ve declared `MyButton`, you can nest it into another component: ``` export default function MyApp() { return ( <div> <h1>Welcome to my app</h1> <MyButton /> </div> ); } ``` Notice that `<MyButton />` starts with a capital letter. That’s how you know it’s a React component. React component names must always start with a capital letter, while HTML tags must be lowercase. Have a look at the result: App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` function MyButton() { return ( <button> I'm a button </button> ); } export default function MyApp() { return ( <div> <h1>Welcome to my app</h1> <MyButton /> </div> ); } ``` Show more The `export default` keywords specify the main component in the file. If you’re not familiar with some piece of JavaScript syntax, [MDN](https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export) and [javascript.info](https://javascript.info/import-export) have great references. ## Writing markup with JSX[Link for Writing markup with JSX]() The markup syntax you’ve seen above is called *JSX*. It is optional, but most React projects use JSX for its convenience. All of the [tools we recommend for local development](https://react.dev/learn/installation) support JSX out of the box. JSX is stricter than HTML. You have to close tags like `<br />`. Your component also can’t return multiple JSX tags. You have to wrap them into a shared parent, like a `<div>...</div>` or an empty `<>...</>` wrapper: ``` function AboutPage() { return ( <> <h1>About</h1> <p>Hello there.<br />How do you do?</p> </> ); } ``` If you have a lot of HTML to port to JSX, you can use an [online converter.](https://transform.tools/html-to-jsx) ## Adding styles[Link for Adding styles]() In React, you specify a CSS class with `className`. It works the same way as the HTML [`class`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class) attribute: ``` <img className="avatar" /> ``` Then you write the CSS rules for it in a separate CSS file: ``` /* In your CSS */ .avatar { border-radius: 50%; } ``` React does not prescribe how you add CSS files. In the simplest case, you’ll add a [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link) tag to your HTML. If you use a build tool or a framework, consult its documentation to learn how to add a CSS file to your project. ## Displaying data[Link for Displaying data]() JSX lets you put markup into JavaScript. Curly braces let you “escape back” into JavaScript so that you can embed some variable from your code and display it to the user. For example, this will display `user.name`: ``` return ( <h1> {user.name} </h1> ); ``` You can also “escape into JavaScript” from JSX attributes, but you have to use curly braces *instead of* quotes. For example, `className="avatar"` passes the `"avatar"` string as the CSS class, but `src={user.imageUrl}` reads the JavaScript `user.imageUrl` variable value, and then passes that value as the `src` attribute: ``` return ( <img className="avatar" src={user.imageUrl} /> ); ``` You can put more complex expressions inside the JSX curly braces too, for example, [string concatenation](https://javascript.info/operators): App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` const user = { name: 'Hedy Lamarr', imageUrl: 'https://i.imgur.com/yXOvdOSs.jpg', imageSize: 90, }; export default function Profile() { return ( <> <h1>{user.name}</h1> <img className="avatar" src={user.imageUrl} alt={'Photo of ' + user.name} style={{ width: user.imageSize, height: user.imageSize }} /> </> ); } ``` Show more In the above example, `style={{}}` is not a special syntax, but a regular `{}` object inside the `style={ }` JSX curly braces. You can use the `style` attribute when your styles depend on JavaScript variables. ## Conditional rendering[Link for Conditional rendering]() In React, there is no special syntax for writing conditions. Instead, you’ll use the same techniques as you use when writing regular JavaScript code. For example, you can use an [`if`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) statement to conditionally include JSX: ``` let content; if (isLoggedIn) { content = <AdminPanel />; } else { content = <LoginForm />; } return ( <div> {content} </div> ); ``` If you prefer more compact code, you can use the [conditional `?` operator.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) Unlike `if`, it works inside JSX: ``` <div> {isLoggedIn ? ( <AdminPanel /> ) : ( <LoginForm /> )} </div> ``` When you don’t need the `else` branch, you can also use a shorter [logical `&&` syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND): ``` <div> {isLoggedIn && <AdminPanel />} </div> ``` All of these approaches also work for conditionally specifying attributes. If you’re unfamiliar with some of this JavaScript syntax, you can start by always using `if...else`. ## Rendering lists[Link for Rendering lists]() You will rely on JavaScript features like [`for` loop](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for) and the [array `map()` function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) to render lists of components. For example, let’s say you have an array of products: ``` const products = [ { title: 'Cabbage', id: 1 }, { title: 'Garlic', id: 2 }, { title: 'Apple', id: 3 }, ]; ``` Inside your component, use the `map()` function to transform an array of products into an array of `<li>` items: ``` const listItems = products.map(product => <li key={product.id}> {product.title} </li> ); return ( <ul>{listItems}</ul> ); ``` Notice how `<li>` has a `key` attribute. For each item in a list, you should pass a string or a number that uniquely identifies that item among its siblings. Usually, a key should be coming from your data, such as a database ID. React uses your keys to know what happened if you later insert, delete, or reorder the items. App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` const products = [ { title: 'Cabbage', isFruit: false, id: 1 }, { title: 'Garlic', isFruit: false, id: 2 }, { title: 'Apple', isFruit: true, id: 3 }, ]; export default function ShoppingList() { const listItems = products.map(product => <li key={product.id} style={{ color: product.isFruit ? 'magenta' : 'darkgreen' }} > {product.title} </li> ); return ( <ul>{listItems}</ul> ); } ``` Show more ## Responding to events[Link for Responding to events]() You can respond to events by declaring *event handler* functions inside your components: ``` function MyButton() { function handleClick() { alert('You clicked me!'); } return ( <button onClick={handleClick}> Click me </button> ); } ``` Notice how `onClick={handleClick}` has no parentheses at the end! Do not *call* the event handler function: you only need to *pass it down*. React will call your event handler when the user clicks the button. ## Updating the screen[Link for Updating the screen]() Often, you’ll want your component to “remember” some information and display it. For example, maybe you want to count the number of times a button is clicked. To do this, add *state* to your component. First, import [`useState`](https://react.dev/reference/react/useState) from React: ``` import { useState } from 'react'; ``` Now you can declare a *state variable* inside your component: ``` function MyButton() { const [count, setCount] = useState(0); // ... ``` You’ll get two things from `useState`: the current state (`count`), and the function that lets you update it (`setCount`). You can give them any names, but the convention is to write `[something, setSomething]`. The first time the button is displayed, `count` will be `0` because you passed `0` to `useState()`. When you want to change state, call `setCount()` and pass the new value to it. Clicking this button will increment the counter: ``` function MyButton() { const [count, setCount] = useState(0); function handleClick() { setCount(count + 1); } return ( <button onClick={handleClick}> Clicked {count} times </button> ); } ``` React will call your component function again. This time, `count` will be `1`. Then it will be `2`. And so on. If you render the same component multiple times, each will get its own state. Click each button separately: App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` import { useState } from 'react'; export default function MyApp() { return ( <div> <h1>Counters that update separately</h1> <MyButton /> <MyButton /> </div> ); } function MyButton() { const [count, setCount] = useState(0); function handleClick() { setCount(count + 1); } return ( <button onClick={handleClick}> Clicked {count} times </button> ); } ``` Show more Notice how each button “remembers” its own `count` state and doesn’t affect other buttons. ## Using Hooks[Link for Using Hooks]() Functions starting with `use` are called *Hooks*. `useState` is a built-in Hook provided by React. You can find other built-in Hooks in the [API reference.](https://react.dev/reference/react) You can also write your own Hooks by combining the existing ones. Hooks are more restrictive than other functions. You can only call Hooks *at the top* of your components (or other Hooks). If you want to use `useState` in a condition or a loop, extract a new component and put it there. ## Sharing data between components[Link for Sharing data between components]() In the previous example, each `MyButton` had its own independent `count`, and when each button was clicked, only the `count` for the button clicked changed: ![Diagram showing a tree of three components, one parent labeled MyApp and two children labeled MyButton. Both MyButton components contain a count with value zero.](/_next/image?url=%2Fimages%2Fdocs%2Fdiagrams%2Fsharing_data_child.dark.png&w=828&q=75) ![Diagram showing a tree of three components, one parent labeled MyApp and two children labeled MyButton. Both MyButton components contain a count with value zero.](/_next/image?url=%2Fimages%2Fdocs%2Fdiagrams%2Fsharing_data_child.png&w=828&q=75) Initially, each `MyButton`’s `count` state is `0` ![The same diagram as the previous, with the count of the first child MyButton component highlighted indicating a click with the count value incremented to one. The second MyButton component still contains value zero.](/_next/image?url=%2Fimages%2Fdocs%2Fdiagrams%2Fsharing_data_child_clicked.dark.png&w=828&q=75) ![The same diagram as the previous, with the count of the first child MyButton component highlighted indicating a click with the count value incremented to one. The second MyButton component still contains value zero.](/_next/image?url=%2Fimages%2Fdocs%2Fdiagrams%2Fsharing_data_child_clicked.png&w=828&q=75) The first `MyButton` updates its `count` to `1` However, often you’ll need components to *share data and always update together*. To make both `MyButton` components display the same `count` and update together, you need to move the state from the individual buttons “upwards” to the closest component containing all of them. In this example, it is `MyApp`: ![Diagram showing a tree of three components, one parent labeled MyApp and two children labeled MyButton. MyApp contains a count value of zero which is passed down to both of the MyButton components, which also show value zero.](/_next/image?url=%2Fimages%2Fdocs%2Fdiagrams%2Fsharing_data_parent.dark.png&w=828&q=75) ![Diagram showing a tree of three components, one parent labeled MyApp and two children labeled MyButton. MyApp contains a count value of zero which is passed down to both of the MyButton components, which also show value zero.](/_next/image?url=%2Fimages%2Fdocs%2Fdiagrams%2Fsharing_data_parent.png&w=828&q=75) Initially, `MyApp`’s `count` state is `0` and is passed down to both children ![The same diagram as the previous, with the count of the parent MyApp component highlighted indicating a click with the value incremented to one. The flow to both of the children MyButton components is also highlighted, and the count value in each child is set to one indicating the value was passed down.](/_next/image?url=%2Fimages%2Fdocs%2Fdiagrams%2Fsharing_data_parent_clicked.dark.png&w=828&q=75) ![The same diagram as the previous, with the count of the parent MyApp component highlighted indicating a click with the value incremented to one. The flow to both of the children MyButton components is also highlighted, and the count value in each child is set to one indicating the value was passed down.](/_next/image?url=%2Fimages%2Fdocs%2Fdiagrams%2Fsharing_data_parent_clicked.png&w=828&q=75) On click, `MyApp` updates its `count` state to `1` and passes it down to both children Now when you click either button, the `count` in `MyApp` will change, which will change both of the counts in `MyButton`. Here’s how you can express this in code. First, *move the state up* from `MyButton` into `MyApp`: ``` export default function MyApp() { const [count, setCount] = useState(0); function handleClick() { setCount(count + 1); } return ( <div> <h1>Counters that update separately</h1> <MyButton /> <MyButton /> </div> ); } function MyButton() { // ... we're moving code from here ... } ``` Then, *pass the state down* from `MyApp` to each `MyButton`, together with the shared click handler. You can pass information to `MyButton` using the JSX curly braces, just like you previously did with built-in tags like `<img>`: ``` export default function MyApp() { const [count, setCount] = useState(0); function handleClick() { setCount(count + 1); } return ( <div> <h1>Counters that update together</h1> <MyButton count={count} onClick={handleClick} /> <MyButton count={count} onClick={handleClick} /> </div> ); } ``` The information you pass down like this is called *props*. Now the `MyApp` component contains the `count` state and the `handleClick` event handler, and *passes both of them down as props* to each of the buttons. Finally, change `MyButton` to *read* the props you have passed from its parent component: ``` function MyButton({ count, onClick }) { return ( <button onClick={onClick}> Clicked {count} times </button> ); } ``` When you click the button, the `onClick` handler fires. Each button’s `onClick` prop was set to the `handleClick` function inside `MyApp`, so the code inside of it runs. That code calls `setCount(count + 1)`, incrementing the `count` state variable. The new `count` value is passed as a prop to each button, so they all show the new value. This is called “lifting state up”. By moving state up, you’ve shared it between components. App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` import { useState } from 'react'; export default function MyApp() { const [count, setCount] = useState(0); function handleClick() { setCount(count + 1); } return ( <div> <h1>Counters that update together</h1> <MyButton count={count} onClick={handleClick} /> <MyButton count={count} onClick={handleClick} /> </div> ); } function MyButton({ count, onClick }) { return ( <button onClick={onClick}> Clicked {count} times </button> ); } ``` Show more ## Next Steps[Link for Next Steps]() By now, you know the basics of how to write React code! Check out the [Tutorial](https://react.dev/learn/tutorial-tic-tac-toe) to put them into practice and build your first mini-app with React. [NextTutorial: Tic-Tac-Toe](https://react.dev/learn/tutorial-tic-tac-toe)
https://react.dev/learn/add-react-to-an-existing-project
[Learn React](https://react.dev/learn) [Installation](https://react.dev/learn/installation) # Add React to an Existing Project[Link for this heading]() If you want to add some interactivity to your existing project, you don’t have to rewrite it in React. Add React to your existing stack, and render interactive React components anywhere. ### Note **You need to install [Node.js](https://nodejs.org/en/) for local development.** Although you can [try React](https://react.dev/learn/installation) online or with a simple HTML page, realistically most JavaScript tooling you’ll want to use for development requires Node.js. ## Using React for an entire subroute of your existing website[Link for Using React for an entire subroute of your existing website]() Let’s say you have an existing web app at `example.com` built with another server technology (like Rails), and you want to implement all routes starting with `example.com/some-app/` fully with React. Here’s how we recommend to set it up: 1. **Build the React part of your app** using one of the [React-based frameworks](https://react.dev/learn/start-a-new-react-project). 2. **Specify `/some-app` as the *base path*** in your framework’s configuration (here’s how: [Next.js](https://nextjs.org/docs/api-reference/next.config.js/basepath), [Gatsby](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)). 3. **Configure your server or a proxy** so that all requests under `/some-app/` are handled by your React app. This ensures the React part of your app can [benefit from the best practices](https://react.dev/learn/start-a-new-react-project) baked into those frameworks. Many React-based frameworks are full-stack and let your React app take advantage of the server. However, you can use the same approach even if you can’t or don’t want to run JavaScript on the server. In that case, serve the HTML/CSS/JS export ([`next export` output](https://nextjs.org/docs/advanced-features/static-html-export) for Next.js, default for Gatsby) at `/some-app/` instead. ## Using React for a part of your existing page[Link for Using React for a part of your existing page]() Let’s say you have an existing page built with another technology (either a server one like Rails, or a client one like Backbone), and you want to render interactive React components somewhere on that page. That’s a common way to integrate React—in fact, it’s how most React usage looked at Meta for many years! You can do this in two steps: 1. **Set up a JavaScript environment** that lets you use the [JSX syntax](https://react.dev/learn/writing-markup-with-jsx), split your code into modules with the [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) / [`export`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) syntax, and use packages (for example, React) from the [npm](https://www.npmjs.com/) package registry. 2. **Render your React components** where you want to see them on the page. The exact approach depends on your existing page setup, so let’s walk through some details. ### Step 1: Set up a modular JavaScript environment[Link for Step 1: Set up a modular JavaScript environment]() A modular JavaScript environment lets you write your React components in individual files, as opposed to writing all of your code in a single file. It also lets you use all the wonderful packages published by other developers on the [npm](https://www.npmjs.com/) registry—including React itself! How you do this depends on your existing setup: - **If your app is already split into files that use `import` statements,** try to use the setup you already have. Check whether writing `<div />` in your JS code causes a syntax error. If it causes a syntax error, you might need to [transform your JavaScript code with Babel](https://babeljs.io/setup), and enable the [Babel React preset](https://babeljs.io/docs/babel-preset-react) to use JSX. - **If your app doesn’t have an existing setup for compiling JavaScript modules,** set it up with [Vite](https://vitejs.dev/). The Vite community maintains [many integrations with backend frameworks](https://github.com/vitejs/awesome-vite), including Rails, Django, and Laravel. If your backend framework is not listed, [follow this guide](https://vitejs.dev/guide/backend-integration.html) to manually integrate Vite builds with your backend. To check whether your setup works, run this command in your project folder: Terminal Copy npm install react react-dom Then add these lines of code at the top of your main JavaScript file (it might be called `index.js` or `main.js`): index.js index.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` import { createRoot } from 'react-dom/client'; // Clear the existing HTML content document.body.innerHTML = '<div id="app"></div>'; // Render your React component instead const root = createRoot(document.getElementById('app')); root.render(<h1>Hello, world</h1>); ``` If the entire content of your page was replaced by a “Hello, world!”, everything worked! Keep reading. ### Note Integrating a modular JavaScript environment into an existing project for the first time can feel intimidating, but it’s worth it! If you get stuck, try our [community resources](https://react.dev/community) or the [Vite Chat](https://chat.vitejs.dev/). ### Step 2: Render React components anywhere on the page[Link for Step 2: Render React components anywhere on the page]() In the previous step, you put this code at the top of your main file: ``` import { createRoot } from 'react-dom/client'; // Clear the existing HTML content document.body.innerHTML = '<div id="app"></div>'; // Render your React component instead const root = createRoot(document.getElementById('app')); root.render(<h1>Hello, world</h1>); ``` Of course, you don’t actually want to clear the existing HTML content! Delete this code. Instead, you probably want to render your React components in specific places in your HTML. Open your HTML page (or the server templates that generate it) and add a unique [`id`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id) attribute to any tag, for example: ``` <!-- ... somewhere in your html ... --> <nav id="navigation"></nav> <!-- ... more html ... --> ``` This lets you find that HTML element with [`document.getElementById`](https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById) and pass it to [`createRoot`](https://react.dev/reference/react-dom/client/createRoot) so that you can render your own React component inside: index.jsindex.html index.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` import { createRoot } from 'react-dom/client'; function NavigationBar() { // TODO: Actually implement a navigation bar return <h1>Hello from React!</h1>; } const domNode = document.getElementById('navigation'); const root = createRoot(domNode); root.render(<NavigationBar />); ``` Notice how the original HTML content from `index.html` is preserved, but your own `NavigationBar` React component now appears inside the `<nav id="navigation">` from your HTML. Read the [`createRoot` usage documentation](https://react.dev/reference/react-dom/client/createRoot) to learn more about rendering React components inside an existing HTML page. When you adopt React in an existing project, it’s common to start with small interactive components (like buttons), and then gradually keep “moving upwards” until eventually your entire page is built with React. If you ever reach that point, we recommend migrating to [a React framework](https://react.dev/learn/start-a-new-react-project) right after to get the most out of React. ## Using React Native in an existing native mobile app[Link for Using React Native in an existing native mobile app]() [React Native](https://reactnative.dev/) can also be integrated into existing native apps incrementally. If you have an existing native app for Android (Java or Kotlin) or iOS (Objective-C or Swift), [follow this guide](https://reactnative.dev/docs/integration-with-existing-apps) to add a React Native screen to it. [PreviousStart a New React Project](https://react.dev/learn/start-a-new-react-project) [NextEditor Setup](https://react.dev/learn/editor-setup)
https://react.dev/
![logo by @sawaratsuki1004](/_next/image?url=%2Fimages%2Fuwu.png&w=640&q=75 "logo by @sawaratsuki1004") # React The library for web and native user interfaces [Learn React](https://react.dev/learn)[API Reference](https://react.dev/reference/react) ## Create user interfaces from components React lets you build user interfaces out of individual pieces called components. Create your own React components like `Thumbnail`, `LikeButton`, and `Video`. Then combine them into entire screens, pages, and apps. ### Video.js ``` function Video({ video }) { return ( <div> <Thumbnail video={video} /> <a href={video.url}> <h3>{video.title}</h3> <p>{video.description}</p> </a> <LikeButton video={video} /> </div> ); } ``` []()[**My video** \ Video description]() Whether you work on your own or with thousands of other developers, using React feels the same. It is designed to let you seamlessly combine components written by independent people, teams, and organizations. ## Write components with code and markup React components are JavaScript functions. Want to show some content conditionally? Use an `if` statement. Displaying a list? Try array `map()`. Learning React is learning programming. ### VideoList.js ``` function VideoList({ videos, emptyHeading }) { const count = videos.length; let heading = emptyHeading; if (count > 0) { const noun = count > 1 ? 'Videos' : 'Video'; heading = count + ' ' + noun; } return ( <section> <h2>{heading}</h2> {videos.map(video => <Video key={video.id} video={video} /> )} </section> ); } ``` ## 3 Videos []()[**First video** \ Video description]() []()[**Second video** \ Video description]() []()[**Third video** \ Video description]() This markup syntax is called JSX. It is a JavaScript syntax extension popularized by React. Putting JSX markup close to related rendering logic makes React components easy to create, maintain, and delete. ## Add interactivity wherever you need it React components receive data and return what should appear on the screen. You can pass them new data in response to an interaction, like when the user types into an input. React will then update the screen to match the new data. ### SearchableVideoList.js ``` import { useState } from 'react'; function SearchableVideoList({ videos }) { const [searchText, setSearchText] = useState(''); const foundVideos = filterVideos(videos, searchText); return ( <> <SearchInput value={searchText} onChange={newText => setSearchText(newText)} /> <VideoList videos={foundVideos} emptyHeading={`No matches for “${searchText}”`} /> </> ); } ``` example.com/videos.html # React Videos A brief history of React Search ## 5 Videos [](https://www.youtube.com/watch?v=8pDqJVdNa44)[**React: The Documentary** \ The origin story of React](https://www.youtube.com/watch?v=8pDqJVdNa44) [](https://www.youtube.com/watch?v=x7cQ3mrcKaY)[**Rethinking Best Practices** \ Pete Hunt (2013)](https://www.youtube.com/watch?v=x7cQ3mrcKaY) [](https://www.youtube.com/watch?v=KVZ-P-ZI6W4)[**Introducing React Native** \ Tom Occhino (2015)](https://www.youtube.com/watch?v=KVZ-P-ZI6W4) [](https://www.youtube.com/watch?v=V-QO-KO90iQ)[**Introducing React Hooks** \ Sophie Alpert and Dan Abramov (2018)](https://www.youtube.com/watch?v=V-QO-KO90iQ) [](https://www.youtube.com/watch?v=TQQPAU21ZUw)[**Introducing Server Components** \ Dan Abramov and Lauren Tan (2020)](https://www.youtube.com/watch?v=TQQPAU21ZUw) You don’t have to build your whole page in React. Add React to your existing HTML page, and render interactive React components anywhere on it. [Add React to your page](https://react.dev/learn/add-react-to-an-existing-project) ## Go full-stack with a framework React is a library. It lets you put components together, but it doesn’t prescribe how to do routing and data fetching. To build an entire app with React, we recommend a full-stack React framework like [Next.js](https://nextjs.org) or [Remix](https://remix.run). ### confs/\[slug].js ``` import { db } from './database.js'; import { Suspense } from 'react'; async function ConferencePage({ slug }) { const conf = await db.Confs.find({ slug }); return ( <ConferenceLayout conf={conf}> <Suspense fallback={<TalksLoading />}> <Talks confId={conf.id} /> </Suspense> </ConferenceLayout> ); } async function Talks({ confId }) { const talks = await db.Talks.findAll({ confId }); const videos = talks.map(talk => talk.video); return <SearchableVideoList videos={videos} />; } ``` example.com/confs/react-conf-2021 React Conf 2021React Conf 2019 ![](/images/home/conf2021/cover.svg) Search ## 19 Videos [![](/images/home/conf2021/andrew.jpg)![](/images/home/conf2021/lauren.jpg)![](/images/home/conf2021/juan.jpg)![](/images/home/conf2021/rick.jpg) \ React Conf](https://www.youtube.com/watch?v=FZ0cG47msEk&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=1) [**React 18 Keynote** \ The React Team](https://www.youtube.com/watch?v=FZ0cG47msEk&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=1) [![](/images/home/conf2021/shruti.jpg) \ React Conf](https://www.youtube.com/watch?v=ytudH8je5ko&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=2) [**React 18 for App Developers** \ Shruti Kapoor](https://www.youtube.com/watch?v=ytudH8je5ko&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=2) [![](/images/home/conf2021/shaundai.jpg) \ React Conf](https://www.youtube.com/watch?v=pj5N-Khihgc&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=3) [**Streaming Server Rendering with Suspense** \ Shaundai Person](https://www.youtube.com/watch?v=pj5N-Khihgc&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=3) [![](/images/home/conf2021/aakansha.jpg) \ React Conf](https://www.youtube.com/watch?v=qn7gRClrC9U&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=4) [**The First React Working Group** \ Aakansha Doshi](https://www.youtube.com/watch?v=qn7gRClrC9U&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=4) [![](/images/home/conf2021/brian.jpg) \ React Conf](https://www.youtube.com/watch?v=oxDfrke8rZg&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=5) [**React Developer Tooling** \ Brian Vaughn](https://www.youtube.com/watch?v=oxDfrke8rZg&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=5) [![](/images/home/conf2021/xuan.jpg) \ React Conf](https://www.youtube.com/watch?v=lGEMwh32soc&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=6) [**React without memo** \ Xuan Huang (黄玄)](https://www.youtube.com/watch?v=lGEMwh32soc&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=6) [![](/images/home/conf2021/rachel.jpg) \ React Conf](https://www.youtube.com/watch?v=mneDaMYOKP8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=7) [**React Docs Keynote** \ Rachel Nabors](https://www.youtube.com/watch?v=mneDaMYOKP8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=7) [![](/images/home/conf2021/debbie.jpg) \ React Conf](https://www.youtube.com/watch?v=-7odLW_hG7s&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=8) [**Things I Learnt from the New React Docs** \ Debbie O'Brien](https://www.youtube.com/watch?v=-7odLW_hG7s&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=8) [![](/images/home/conf2021/sarah.jpg) \ React Conf](https://www.youtube.com/watch?v=5X-WEQflCL0&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=9) [**Learning in the Browser** \ Sarah Rainsberger](https://www.youtube.com/watch?v=5X-WEQflCL0&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=9) [![](/images/home/conf2021/linton.jpg) \ React Conf](https://www.youtube.com/watch?v=7cPWmID5XAk&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=10) [**The ROI of Designing with React** \ Linton Ye](https://www.youtube.com/watch?v=7cPWmID5XAk&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=10) [![](/images/home/conf2021/delba.jpg) \ React Conf](https://www.youtube.com/watch?v=zL8cz2W0z34&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=11) [**Interactive Playgrounds with React** \ Delba de Oliveira](https://www.youtube.com/watch?v=zL8cz2W0z34&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=11) [![](/images/home/conf2021/robert.jpg) \ React Conf](https://www.youtube.com/watch?v=lhVGdErZuN4&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=12) [**Re-introducing Relay** \ Robert Balicki](https://www.youtube.com/watch?v=lhVGdErZuN4&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=12) [![](/images/home/conf2021/eric.jpg)![](/images/home/conf2021/steven.jpg) \ React Conf](https://www.youtube.com/watch?v=9L4FFrvwJwY&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=13) [**React Native Desktop** \ Eric Rozell and Steven Moyes](https://www.youtube.com/watch?v=9L4FFrvwJwY&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=13) [![](/images/home/conf2021/roman.jpg) \ React Conf](https://www.youtube.com/watch?v=NLj73vrc2I8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=14) [**On-device Machine Learning for React Native** \ Roman Rädle](https://www.youtube.com/watch?v=NLj73vrc2I8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=14) [![](/images/home/conf2021/daishi.jpg) \ React Conf](https://www.youtube.com/watch?v=oPfSC5bQPR8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=15) [**React 18 for External Store Libraries** \ Daishi Kato](https://www.youtube.com/watch?v=oPfSC5bQPR8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=15) [![](/images/home/conf2021/diego.jpg) \ React Conf](https://www.youtube.com/watch?v=dcm8fjBfro8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=16) [**Building Accessible Components with React 18** \ Diego Haz](https://www.youtube.com/watch?v=dcm8fjBfro8&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=16) [![](/images/home/conf2021/tafu.jpg) \ React Conf](https://www.youtube.com/watch?v=S4a0QlsH0pU&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=17) [**Accessible Japanese Form Components with React** \ Tafu Nakazaki](https://www.youtube.com/watch?v=S4a0QlsH0pU&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=17) [![](/images/home/conf2021/lyle.jpg) \ React Conf](https://www.youtube.com/watch?v=b3l4WxipFsE&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=18) [**UI Tools for Artists** \ Lyle Troxell](https://www.youtube.com/watch?v=b3l4WxipFsE&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=18) [![](/images/home/conf2021/helen.jpg) \ React Conf](https://www.youtube.com/watch?v=HS6vIYkSNks&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=19) [**Hydrogen + React 18** \ Helen Lin](https://www.youtube.com/watch?v=HS6vIYkSNks&list=PLNG_1j3cPCaZZ7etkzWA7JfdmKWT0pMsa&index=19) React is also an architecture. Frameworks that implement it let you fetch data in asynchronous components that run on the server or even during the build. Read data from a file or a database, and pass it down to your interactive components. [Get started with a framework](https://react.dev/learn/start-a-new-react-project) ## Use the best from every platform People love web and native apps for different reasons. React lets you build both web apps and native apps using the same skills. It leans upon each platform’s unique strengths to let your interfaces feel just right on every platform. example.com #### Stay true to the web People expect web app pages to load fast. On the server, React lets you start streaming HTML while you’re still fetching data, progressively filling in the remaining content before any JavaScript code loads. On the client, React can use standard web APIs to keep your UI responsive even in the middle of rendering. 12:23 PM #### Go truly native People expect native apps to look and feel like their platform. [React Native](https://reactnative.dev) and [Expo](https://github.com/expo/expo) let you build apps in React for Android, iOS, and more. They look and feel native because their UIs *are* truly native. It’s not a web view—your React components render real Android and iOS views provided by the platform. With React, you can be a web *and* a native developer. Your team can ship to many platforms without sacrificing the user experience. Your organization can bridge the platform silos, and form teams that own entire features end-to-end. [Build for native platforms](https://reactnative.dev/) ## Upgrade when the future is ready React approaches changes with care. Every React commit is tested on business-critical surfaces with over a billion users. Over 100,000 React components at Meta help validate every migration strategy. The React team is always researching how to improve React. Some research takes years to pay off. React has a high bar for taking a research idea into production. Only proven approaches become a part of React. [Read more React news](https://react.dev/blog) Latest React News [**React 19** \ December 05, 2024](https://react.dev/blog/2024/12/05/react-19) [**React Compiler Beta Release and Roadmap** \ October 21, 2024](https://react.dev/blog/2024/10/21/react-compiler-beta-release) [**React Conf 2024 Recap** \ May 22, 2024](https://react.dev/blog/2024/05/22/react-conf-2024-recap) [**React 19 RC** \ April 25, 2024](https://react.dev/blog/2024/04/25/react-19) [Read more React news](https://react.dev/blog) ## Join a community of millions You’re not alone. Two million developers from all over the world visit the React docs every month. React is something that people and teams can agree on. ![People singing karaoke at React Conf](/images/home/community/react_conf_fun.webp) ![Sunil Pai speaking at React India](/images/home/community/react_india_sunil.webp) ![A hallway conversation between two people at React Conf](/images/home/community/react_conf_hallway.webp) ![A hallway conversation at React India](/images/home/community/react_india_hallway.webp) ![Elizabet Oliveira speaking at React Conf](/images/home/community/react_conf_elizabet.webp) ![People taking a group selfie at React India](/images/home/community/react_india_selfie.webp) ![Nat Alison speaking at React Conf](/images/home/community/react_conf_nat.webp) ![Organizers greeting attendees at React India](/images/home/community/react_india_team.webp) ![People singing karaoke at React Conf](/images/home/community/react_conf_fun.webp) ![Sunil Pai speaking at React India](/images/home/community/react_india_sunil.webp) ![A hallway conversation between two people at React Conf](/images/home/community/react_conf_hallway.webp) ![A hallway conversation at React India](/images/home/community/react_india_hallway.webp) ![Elizabet Oliveira speaking at React Conf](/images/home/community/react_conf_elizabet.webp) ![People taking a group selfie at React India](/images/home/community/react_india_selfie.webp) ![Nat Alison speaking at React Conf](/images/home/community/react_conf_nat.webp) ![Organizers greeting attendees at React India](/images/home/community/react_india_team.webp) This is why React is more than a library, an architecture, or even an ecosystem. React is a community. It’s a place where you can ask for help, find opportunities, and meet new friends. You will meet both developers and designers, beginners and experts, researchers and artists, teachers and students. Our backgrounds may be very different, but React lets us all create user interfaces together. ![logo by @sawaratsuki1004](/images/uwu.png "logo by @sawaratsuki1004") ## Welcome to the React community [Get Started](https://react.dev/learn)
https://react.dev/learn/start-a-new-react-project
[Learn React](https://react.dev/learn) [Installation](https://react.dev/learn/installation) # Start a New React Project[Link for this heading]() If you want to build a new app or a new website fully with React, we recommend picking one of the React-powered frameworks popular in the community. You can use React without a framework, however we’ve found that most apps and sites eventually build solutions to common problems such as code-splitting, routing, data fetching, and generating HTML. These problems are common to all UI libraries, not just React. By starting with a framework, you can get started with React quickly, and avoid essentially building your own framework later. ##### Deep Dive #### Can I use React without a framework?[Link for Can I use React without a framework?]() Show Details You can definitely use React without a framework—that’s how you’d [use React for a part of your page.](https://react.dev/learn/add-react-to-an-existing-project) **However, if you’re building a new app or a site fully with React, we recommend using a framework.** Here’s why. Even if you don’t need routing or data fetching at first, you’ll likely want to add some libraries for them. As your JavaScript bundle grows with every new feature, you might have to figure out how to split code for every route individually. As your data fetching needs get more complex, you are likely to encounter server-client network waterfalls that make your app feel very slow. As your audience includes more users with poor network conditions and low-end devices, you might need to generate HTML from your components to display content early—either on the server, or during the build time. Changing your setup to run some of your code on the server or during the build can be very tricky. **These problems are not React-specific. This is why Svelte has SvelteKit, Vue has Nuxt, and so on.** To solve these problems on your own, you’ll need to integrate your bundler with your router and with your data fetching library. It’s not hard to get an initial setup working, but there are a lot of subtleties involved in making an app that loads quickly even as it grows over time. You’ll want to send down the minimal amount of app code but do so in a single client–server roundtrip, in parallel with any data required for the page. You’ll likely want the page to be interactive before your JavaScript code even runs, to support progressive enhancement. You may want to generate a folder of fully static HTML files for your marketing pages that can be hosted anywhere and still work with JavaScript disabled. Building these capabilities yourself takes real work. **React frameworks on this page solve problems like these by default, with no extra work from your side.** They let you start very lean and then scale your app with your needs. Each React framework has a community, so finding answers to questions and upgrading tooling is easier. Frameworks also give structure to your code, helping you and others retain context and skills between different projects. Conversely, with a custom setup it’s easier to get stuck on unsupported dependency versions, and you’ll essentially end up creating your own framework—albeit one with no community or upgrade path (and if it’s anything like the ones we’ve made in the past, more haphazardly designed). If your app has unusual constraints not served well by these frameworks, or you prefer to solve these problems yourself, you can roll your own custom setup with React. Grab `react` and `react-dom` from npm, set up your custom build process with a bundler like [Vite](https://vitejs.dev/) or [Parcel](https://parceljs.org/), and add other tools as you need them for routing, static generation or server-side rendering, and more. ## Production-grade React frameworks[Link for Production-grade React frameworks]() These frameworks support all the features you need to deploy and scale your app in production and are working towards supporting our [full-stack architecture vision](). All of the frameworks we recommend are open source with active communities for support, and can be deployed to your own server or a hosting provider. If you’re a framework author interested in being included on this list, [please let us know](https://github.com/reactjs/react.dev/issues/new?assignees=&labels=type%3A%20framework&projects=&template=3-framework.yml&title=%5BFramework%5D%3A%20). ### Next.js[Link for Next.js]() **[Next.js’ Pages Router](https://nextjs.org/) is a full-stack React framework.** It’s versatile and lets you create React apps of any size—from a mostly static blog to a complex dynamic application. To create a new Next.js project, run in your terminal: Terminal Copy npx create-next-app@latest If you’re new to Next.js, check out the [learn Next.js course.](https://nextjs.org/learn) Next.js is maintained by [Vercel](https://vercel.com/). You can [deploy a Next.js app](https://nextjs.org/docs/app/building-your-application/deploying) to any Node.js or serverless hosting, or to your own server. Next.js also supports a [static export](https://nextjs.org/docs/pages/building-your-application/deploying/static-exports) which doesn’t require a server. ### Remix[Link for Remix]() **[Remix](https://remix.run/) is a full-stack React framework with nested routing.** It lets you break your app into nested parts that can load data in parallel and refresh in response to the user actions. To create a new Remix project, run: Terminal Copy npx create-remix If you’re new to Remix, check out the Remix [blog tutorial](https://remix.run/docs/en/main/tutorials/blog) (short) and [app tutorial](https://remix.run/docs/en/main/tutorials/jokes) (long). Remix is maintained by [Shopify](https://www.shopify.com/). When you create a Remix project, you need to [pick your deployment target](https://remix.run/docs/en/main/guides/deployment). You can deploy a Remix app to any Node.js or serverless hosting by using or writing an [adapter](https://remix.run/docs/en/main/other-api/adapter). ### Gatsby[Link for Gatsby]() **[Gatsby](https://www.gatsbyjs.com/) is a React framework for fast CMS-backed websites.** Its rich plugin ecosystem and its GraphQL data layer simplify integrating content, APIs, and services into one website. To create a new Gatsby project, run: Terminal Copy npx create-gatsby If you’re new to Gatsby, check out the [Gatsby tutorial.](https://www.gatsbyjs.com/docs/tutorial/) Gatsby is maintained by [Netlify](https://www.netlify.com/). You can [deploy a fully static Gatsby site](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting) to any static hosting. If you opt into using server-only features, make sure your hosting provider supports them for Gatsby. ### Expo (for native apps)[Link for Expo (for native apps)]() **[Expo](https://expo.dev/) is a React framework that lets you create universal Android, iOS, and web apps with truly native UIs.** It provides an SDK for [React Native](https://reactnative.dev/) that makes the native parts easier to use. To create a new Expo project, run: Terminal Copy npx create-expo-app If you’re new to Expo, check out the [Expo tutorial](https://docs.expo.dev/tutorial/introduction/). Expo is maintained by [Expo (the company)](https://expo.dev/about). Building apps with Expo is free, and you can submit them to the Google and Apple app stores without restrictions. Expo additionally provides opt-in paid cloud services. ## Bleeding-edge React frameworks[Link for Bleeding-edge React frameworks]() As we’ve explored how to continue improving React, we realized that integrating React more closely with frameworks (specifically, with routing, bundling, and server technologies) is our biggest opportunity to help React users build better apps. The Next.js team has agreed to collaborate with us in researching, developing, integrating, and testing framework-agnostic bleeding-edge React features like [React Server Components.](https://react.dev/blog/2023/03/22/react-labs-what-we-have-been-working-on-march-2023) These features are getting closer to being production-ready every day, and we’ve been in talks with other bundler and framework developers about integrating them. Our hope is that in a year or two, all frameworks listed on this page will have full support for these features. (If you’re a framework author interested in partnering with us to experiment with these features, please let us know!) ### Next.js (App Router)[Link for Next.js (App Router)]() **[Next.js’s App Router](https://nextjs.org/docs) is a redesign of the Next.js APIs aiming to fulfill the React team’s full-stack architecture vision.** It lets you fetch data in asynchronous components that run on the server or even during the build. Next.js is maintained by [Vercel](https://vercel.com/). You can [deploy a Next.js app](https://nextjs.org/docs/app/building-your-application/deploying) to any Node.js or serverless hosting, or to your own server. Next.js also supports [static export](https://nextjs.org/docs/app/building-your-application/deploying/static-exports) which doesn’t require a server. ##### Deep Dive #### Which features make up the React team’s full-stack architecture vision?[Link for Which features make up the React team’s full-stack architecture vision?]() Show Details Next.js’s App Router bundler fully implements the official [React Server Components specification](https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md). This lets you mix build-time, server-only, and interactive components in a single React tree. For example, you can write a server-only React component as an `async` function that reads from a database or from a file. Then you can pass data down from it to your interactive components: ``` // This component runs *only* on the server (or during the build). async function Talks({ confId }) { // 1. You're on the server, so you can talk to your data layer. API endpoint not required. const talks = await db.Talks.findAll({ confId }); // 2. Add any amount of rendering logic. It won't make your JavaScript bundle larger. const videos = talks.map(talk => talk.video); // 3. Pass the data down to the components that will run in the browser. return <SearchableVideoList videos={videos} />; } ``` Next.js’s App Router also integrates [data fetching with Suspense](https://react.dev/blog/2022/03/29/react-v18). This lets you specify a loading state (like a skeleton placeholder) for different parts of your user interface directly in your React tree: ``` <Suspense fallback={<TalksLoading />}> <Talks confId={conf.id} /> </Suspense> ``` Server Components and Suspense are React features rather than Next.js features. However, adopting them at the framework level requires buy-in and non-trivial implementation work. At the moment, the Next.js App Router is the most complete implementation. The React team is working with bundler developers to make these features easier to implement in the next generation of frameworks. [PreviousInstallation](https://react.dev/learn/installation) [NextAdd React to an Existing Project](https://react.dev/learn/add-react-to-an-existing-project)
https://react.dev/blog/2024/05/22/react-conf-2024-recap
[Blog](https://react.dev/blog) # React Conf 2024 Recap[Link for this heading]() May 22, 2024 by [Ricky Hanlon](https://twitter.com/rickhanlonii). * * * Last week we hosted React Conf 2024, a two-day conference in Henderson, Nevada where 700+ attendees gathered in-person to discuss the latest in UI engineering. This was our first in-person conference since 2019, and we were thrilled to be able to bring the community together again. * * * At React Conf 2024, we announced the [React 19 RC](https://react.dev/blog/2024/12/05/react-19), the [React Native New Architecture Beta](https://github.com/reactwg/react-native-new-architecture/discussions/189), and an experimental release of the [React Compiler](https://react.dev/learn/react-compiler). The community also took the stage to announce [React Router v7](https://remix.run/blog/merging-remix-and-react-router), [Universal Server Components](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=20765s) in Expo Router, React Server Components in [RedwoodJS](https://redwoodjs.com/blog/rsc-now-in-redwoodjs), and much more. The entire [day 1](https://www.youtube.com/watch?v=T8TZQ6k4SLE) and [day 2](https://www.youtube.com/watch?v=0ckOUBiuxVY) streams are available online. In this post, we’ll summarize the talks and announcements from the event. ## Day 1[Link for Day 1]() [*Watch the full day 1 stream here.*](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=973s) To kick off day 1, Meta CTO [Andrew “Boz” Bosworth](https://www.threads.net/@boztank) shared a welcome message followed by an introduction by [Seth Webster](https://twitter.com/sethwebster), who manages the React Org at Meta, and our MC [Ashley Narcisse](https://twitter.com/_darkfadr). In the day 1 keynote, [Joe Savona](https://twitter.com/en_JS) shared our goals and vision for React to make it easy for anyone to build great user experiences. [Lauren Tan](https://twitter.com/potetotes) followed with a State of React, where she shared that React was downloaded over 1 billion times in 2023, and that 37% of new developers learn to program with React. Finally, she highlighted the work of the React community to make React, React. For more, check out these talks from the community later in the conference: - [Vanilla React](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=5542s) by [Ryan Florence](https://twitter.com/ryanflorence) - [React Rhythm &amp; Blues](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=12728s) by [Lee Robinson](https://twitter.com/leeerob) - [RedwoodJS, now with React Server Components](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=26815s) by [Amy Dutton](https://twitter.com/selfteachme) - [Introducing Universal React Server Components in Expo Router](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=20765s) by [Evan Bacon](https://twitter.com/Baconbrix) Next in the keynote, [Josh Story](https://twitter.com/joshcstory) and [Andrew Clark](https://twitter.com/acdlite) shared new features coming in React 19, and announced the React 19 RC which is ready for testing in production. Check out all the features in the [React 19 release post](https://react.dev/blog/2024/12/05/react-19), and see these talks for deep dives on the new features: - [What’s new in React 19](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=8880s) by [Lydia Hallie](https://twitter.com/lydiahallie) - [React Unpacked: A Roadmap to React 19](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=10112s) by [Sam Selikoff](https://twitter.com/samselikoff) - [React 19 Deep Dive: Coordinating HTML](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=24916s) by [Josh Story](https://twitter.com/joshcstory) - [Enhancing Forms with React Server Components](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=25280s) by [Aurora Walberg Scharff](https://twitter.com/aurorascharff) - [React for Two Computers](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=18825s) by [Dan Abramov](https://twitter.com/dan_abramov2) - [And Now You Understand React Server Components](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=11256s) by [Kent C. Dodds](https://twitter.com/kentcdodds) Finally, we ended the keynote with [Joe Savona](https://twitter.com/en_JS), [Sathya Gunasekaran](https://twitter.com/_gsathya), and [Mofei Zhang](https://twitter.com/zmofei) announcing that the React Compiler is now [Open Source](https://github.com/facebook/react/pull/29061), and sharing an experimental version of the React Compiler to try out. For more information on using the Compiler and how it works, check out [the docs](https://react.dev/learn/react-compiler) and these talks: - [Forget About Memo](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=12020s) by [Lauren Tan](https://twitter.com/potetotes) - [React Compiler Deep Dive](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=9313s) by [Sathya Gunasekaran](https://twitter.com/_gsathya) and [Mofei Zhang](https://twitter.com/zmofei) Watch the full day 1 keynote here: ## Day 2[Link for Day 2]() [*Watch the full day 2 stream here.*](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=1720s) To kick off day 2, [Seth Webster](https://twitter.com/sethwebster) shared a welcome message, followed by a Thank You from [Eli White](https://x.com/Eli_White) and an introduction by our Chief Vibes Officer [Ashley Narcisse](https://twitter.com/_darkfadr). In the day 2 keynote, [Nicola Corti](https://twitter.com/cortinico) shared the State of React Native, including 78 million downloads in 2023. He also highlighted apps using React Native including 2000+ screens used inside of Meta; the product details page in Facebook Marketplace, which is visited more than 2 billion times per day; and part of the Microsoft Windows Start Menu and some features in almost every Microsoft Office product across mobile and desktop. Nicola also highlighted all the work the community does to support React Native including libraries, frameworks, and multiple platforms. For more, check out these talks from the community: - [Extending React Native beyond Mobile and Desktop Apps](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=5798s) by [Chris Traganos](https://twitter.com/chris_trag) and [Anisha Malde](https://twitter.com/anisha_malde) - [Spatial computing with React](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=22525s) by [Michał Pierzchała](https://twitter.com/thymikee) [Riccardo Cipolleschi](https://twitter.com/cipolleschir) continued the day 2 keynote by announcing that the React Native New Architecture is now in Beta and ready for apps to adopt in production. He shared new features and improvements in the new architecture, and shared the roadmap for the future of React Native. For more check out: - [Cross Platform React](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=26569s) by [Olga Zinoveva](https://github.com/SlyCaptainFlint) and [Naman Goel](https://twitter.com/naman34) Next in the keynote, Nicola announced that we are now recommending starting with a framework like Expo for all new apps created with React Native. With the change, he also announced a new React Native homepage and new Getting Started docs. You can view the new Getting Started guide in the [React Native docs](https://reactnative.dev/docs/next/environment-setup). Finally, to end the keynote, [Kadi Kraman](https://twitter.com/kadikraman) shared the latest features and improvements in Expo, and how to get started developing with React Native using Expo. Watch the full day 2 keynote here: ## Q&amp;A[Link for Q&A]() The React and React Native teams also ended each day with a Q&amp;A session: - [React Q&amp;A](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=27518s) hosted by [Michael Chan](https://twitter.com/chantastic) - [React Native Q&amp;A](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=27935s) hosted by [Jamon Holmgren](https://twitter.com/jamonholmgren) ## And more…[Link for And more…]() We also heard talks on accessibility, error reporting, css, and more: - [Demystifying accessibility in React apps](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=20655s) by [Kateryna Porshnieva](https://twitter.com/krambertech) - [Pigment CSS, CSS in the server component age](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=21696s) by [Olivier Tassinari](https://twitter.com/olivtassinari) - [Real-time React Server Components](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=24070s) by [Sunil Pai](https://twitter.com/threepointone) - [Let’s break React Rules](https://www.youtube.com/watch?v=T8TZQ6k4SLE&t=25862s) by [Charlotte Isambert](https://twitter.com/c_isambert) - [Solve 100% of your errors](https://www.youtube.com/watch?v=0ckOUBiuxVY&t=19881s) by [Ryan Albrecht](https://github.com/ryan953) ## Thank you[Link for Thank you]() Thank you to all the staff, speakers, and participants who made React Conf 2024 possible. There are too many to list, but we want to thank a few in particular. Thank you to [Barbara Markiewicz](https://twitter.com/barbara_markie), the team at [Callstack](https://www.callstack.com/), and our React Team Developer Advocate [Matt Carroll](https://twitter.com/mattcarrollcode) for helping to plan the entire event; and to [Sunny Leggett](https://zeroslopeevents.com/about) and everyone from [Zero Slope](https://zeroslopeevents.com) for helping to organize the event. Thank you [Ashley Narcisse](https://twitter.com/_darkfadr) for being our MC and Chief Vibes Officer; and to [Michael Chan](https://twitter.com/chantastic) and [Jamon Holmgren](https://twitter.com/jamonholmgren) for hosting the Q&amp;A sessions. Thank you [Seth Webster](https://twitter.com/sethwebster) and [Eli White](https://x.com/Eli_White) for welcoming us each day and providing direction on structure and content; and to [Tom Occhino](https://twitter.com/tomocchino) for joining us with a special message during the after-party. Thank you [Ricky Hanlon](https://www.youtube.com/watch?v=FxTZL2U-uKg&t=1263s) for providing detailed feedback on talks, working on slide designs, and generally filling in the gaps to sweat the details. Thank you [Callstack](https://www.callstack.com/) for building the conference website; and to [Kadi Kraman](https://twitter.com/kadikraman) and the [Expo](https://expo.dev/) team for building the conference mobile app. Thank you to all the sponsors who made the event possible: [Remix](https://remix.run/), [Amazon](https://developer.amazon.com/apps-and-games?cmp=US_2024_05_3P_React-Conf-2024&ch=prtnr&chlast=prtnr&pub=ref&publast=ref&type=org&typelast=org), [MUI](https://mui.com/), [Sentry](https://sentry.io/for/react/?utm_source=sponsored-conf&utm_medium=sponsored-event&utm_campaign=frontend-fy25q2-evergreen&utm_content=logo-reactconf2024-learnmore), [Abbott](https://www.jobs.abbott/software), [Expo](https://expo.dev/), [RedwoodJS](https://redwoodjs.com/), and [Vercel](https://vercel.com). Thank you to the AV Team for the visuals, stage, and sound; and to the Westin Hotel for hosting us. Thank you to all the speakers who shared their knowledge and experiences with the community. Finally, thank you to everyone who attended in person and online to show what makes React, React. React is more than a library, it is a community, and it was inspiring to see everyone come together to share and learn together. See you next time! [PreviousReact Compiler Beta Release and Roadmap](https://react.dev/blog/2024/10/21/react-compiler-beta-release) [NextReact 19 RC](https://react.dev/blog/2024/04/25/react-19)
https://react.dev/blog/2024/10/21/react-compiler-beta-release
[Blog](https://react.dev/blog) # React Compiler Beta Release[Link for this heading]() October 21, 2024 by [Lauren Tan](https://twitter.com/potetotes). * * * The React team is excited to share new updates: 1. We’re publishing React Compiler Beta today, so that early adopters and library maintainers can try it and provide feedback. 2. We’re officially supporting React Compiler for apps on React 17+, through an optional `react-compiler-runtime` package. 3. We’re opening up public membership of the [React Compiler Working Group](https://github.com/reactwg/react-compiler) to prepare the community for gradual adoption of the compiler. * * * At [React Conf 2024](https://react.dev/blog/2024/05/22/react-conf-2024-recap), we announced the experimental release of React Compiler, a build-time tool that optimizes your React app through automatic memoization. [You can find an introduction to React Compiler here](https://react.dev/learn/react-compiler). Since the first release, we’ve fixed numerous bugs reported by the React community, received several high quality bug fixes and contributions[1]() to the compiler, made the compiler more resilient to the broad diversity of JavaScript patterns, and have continued to roll out the compiler more widely at Meta. In this post, we want to share what’s next for React Compiler. ## Try React Compiler Beta today[Link for Try React Compiler Beta today]() At [React India 2024](https://www.youtube.com/watch?v=qd5yk2gxbtg), we shared an update on React Compiler. Today, we are excited to announce a new Beta release of React Compiler and ESLint plugin. New betas are published to npm using the `@beta` tag. To install React Compiler Beta: Terminal Copy npm install -D babel-plugin-react-compiler@beta eslint-plugin-react-compiler@beta Or, if you’re using Yarn: Terminal Copy yarn add -D babel-plugin-react-compiler@beta eslint-plugin-react-compiler@beta You can watch [Sathya Gunasekaran’s](https://twitter.com/_gsathya) talk at React India here: ## We recommend everyone use the React Compiler linter today[Link for We recommend everyone use the React Compiler linter today]() React Compiler’s ESLint plugin helps developers proactively identify and correct [Rules of React](https://react.dev/reference/rules) violations. **We strongly recommend everyone use the linter today**. The linter does not require that you have the compiler installed, so you can use it independently, even if you are not ready to try out the compiler. To install the linter only: Terminal Copy npm install -D eslint-plugin-react-compiler@beta Or, if you’re using Yarn: Terminal Copy yarn add -D eslint-plugin-react-compiler@beta After installation you can enable the linter by [adding it to your ESLint config](https://react.dev/learn/react-compiler). Using the linter helps identify Rules of React breakages, making it easier to adopt the compiler when it’s fully released. ## Backwards Compatibility[Link for Backwards Compatibility]() React Compiler produces code that depends on runtime APIs added in React 19, but we’ve since added support for the compiler to also work with React 17 and 18. If you are not on React 19 yet, in the Beta release you can now try out React Compiler by specifying a minimum `target` in your compiler config, and adding `react-compiler-runtime` as a dependency. [You can find docs on this here](https://react.dev/learn/react-compiler). ## Using React Compiler in libraries[Link for Using React Compiler in libraries]() Our initial release was focused on identifying major issues with using the compiler in applications. We’ve gotten great feedback and have substantially improved the compiler since then. We’re now ready for broad feedback from the community, and for library authors to try out the compiler to improve performance and the developer experience of maintaining your library. React Compiler can also be used to compile libraries. Because React Compiler needs to run on the original source code prior to any code transformations, it is not possible for an application’s build pipeline to compile the libraries they use. Hence, our recommendation is for library maintainers to independently compile and test their libraries with the compiler, and ship compiled code to npm. Because your code is pre-compiled, users of your library will not need to have the compiler enabled in order to benefit from the automatic memoization applied to your library. If your library targets apps not yet on React 19, specify a minimum `target` and add `react-compiler-runtime` as a direct dependency. The runtime package will use the correct implementation of APIs depending on the application’s version, and polyfill the missing APIs if necessary. [You can find more docs on this here.](https://react.dev/learn/react-compiler) ## Opening up React Compiler Working Group to everyone[Link for Opening up React Compiler Working Group to everyone]() We previously announced the invite-only [React Compiler Working Group](https://github.com/reactwg/react-compiler) at React Conf to provide feedback, ask questions, and collaborate on the compiler’s experimental release. From today, together with the Beta release of React Compiler, we are opening up Working Group membership to everyone. The goal of the React Compiler Working Group is to prepare the ecosystem for a smooth, gradual adoption of React Compiler by existing applications and libraries. Please continue to file bug reports in the [React repo](https://github.com/facebook/react), but please leave feedback, ask questions, or share ideas in the [Working Group discussion forum](https://github.com/reactwg/react-compiler/discussions). The core team will also use the discussions repo to share our research findings. As the Stable Release gets closer, any important information will also be posted on this forum. ## React Compiler at Meta[Link for React Compiler at Meta]() At [React Conf](https://react.dev/blog/2024/05/22/react-conf-2024-recap), we shared that our rollout of the compiler on Quest Store and Instagram were successful. Since then, we’ve deployed React Compiler across several more major web apps at Meta, including [Facebook](https://www.facebook.com) and [Threads](https://www.threads.net). That means if you’ve used any of these apps recently, you may have had your experience powered by the compiler. We were able to onboard these apps onto the compiler with few code changes required, in a monorepo with more than 100,000 React components. We’ve seen notable performance improvements across all of these apps. As we’ve rolled out, we’re continuing to see results on the order of [the wins we shared previously at ReactConf](https://youtu.be/lyEKhv8-3n0?t=3223). These apps have already been heavily hand tuned and optimized by Meta engineers and React experts over the years, so even improvements on the order of a few percent are a huge win for us. We also expected developer productivity wins from React Compiler. To measure this, we collaborated with our data science partners at Meta[2]() to conduct a thorough statistical analysis of the impact of manual memoization on productivity. Before rolling out the compiler at Meta, we discovered that only about 8% of React pull requests used manual memoization and that these pull requests took 31-46% longer to author[3](). This confirmed our intuition that manual memoization introduces cognitive overhead, and we anticipate that React Compiler will lead to more efficient code authoring and review. Notably, React Compiler also ensures that *all* code is memoized by default, not just the (in our case) 8% where developers explicitly apply memoization. ## Roadmap to Stable[Link for Roadmap to Stable]() *This is not a final roadmap, and is subject to change.* We intend to ship a Release Candidate of the compiler in the near future following the Beta release, when the majority of apps and libraries that follow the Rules of React have been proven to work well with the compiler. After a period of final feedback from the community, we plan on a Stable Release for the compiler. The Stable Release will mark the beginning of a new foundation for React, and all apps and libraries will be strongly recommended to use the compiler and ESLint plugin. - ✅ Experimental: Released at React Conf 2024, primarily for feedback from early adopters. - ✅ Public Beta: Available today, for feedback from the wider community. - 🚧 Release Candidate (RC): React Compiler works for the majority of rule-following apps and libraries without issue. - 🚧 General Availability: After final feedback period from the community. These releases also include the compiler’s ESLint plugin, which surfaces diagnostics statically analyzed by the compiler. We plan to combine the existing eslint-plugin-react-hooks plugin with the compiler’s ESLint plugin, so only one plugin needs to be installed. Post-Stable, we plan to add more compiler optimizations and improvements. This includes both continual improvements to automatic memoization, and new optimizations altogether, with minimal to no change of product code. Upgrading to each new release of the compiler is aimed to be straightforward, and each upgrade will continue to improve performance and add better handling of diverse JavaScript and React patterns. Throughout this process, we also plan to prototype an IDE extension for React. It is still very early in research, so we expect to be able to share more of our findings with you in a future React Labs blog post. * * * Thanks to [Sathya Gunasekaran](https://twitter.com/_gsathya), [Joe Savona](https://twitter.com/en_JS), [Ricky Hanlon](https://twitter.com/rickhanlonii), [Alex Taylor](https://github.com/alexmckenley), [Jason Bonta](https://twitter.com/someextent), and [Eli White](https://twitter.com/Eli_White) for reviewing and editing this post. * * * ## Footnotes[Link for Footnotes]() 1. Thanks [@nikeee](https://github.com/facebook/react/pulls?q=is%3Apr%20author%3Anikeee), [@henryqdineen](https://github.com/facebook/react/pulls?q=is%3Apr%20author%3Ahenryqdineen), [@TrickyPi](https://github.com/facebook/react/pulls?q=is%3Apr%20author%3ATrickyPi), and several others for their contributions to the compiler. [↩]() 2. Thanks [Vaishali Garg](https://www.linkedin.com/in/vaishaligarg09) for leading this study on React Compiler at Meta, and for reviewing this post. [↩]() 3. After controlling on author tenure, diff length/complexity, and other potential confounding factors. [↩]() [PreviousReact 19](https://react.dev/blog/2024/12/05/react-19) [NextReact Conf 2024 Recap](https://react.dev/blog/2024/05/22/react-conf-2024-recap)
https://react.dev/blog/2024/12/05/react-19
[Blog](https://react.dev/blog) # React v19[Link for this heading]() December 05, 2024 by [The React Team](https://react.dev/community/team) * * * ### Note ### React 19 is now stable\![Link for React 19 is now stable!]() Additions since this post was originally shared with the React 19 RC in April: - **Pre-warming for suspended trees**: see [Improvements to Suspense](https://react.dev/blog/2024/04/25/react-19-upgrade-guide). - **React DOM static APIs**: see [New React DOM Static APIs](). *The date for this post has been updated to reflect the stable release date.* React v19 is now available on npm! In our [React 19 Upgrade Guide](https://react.dev/blog/2024/04/25/react-19-upgrade-guide), we shared step-by-step instructions for upgrading your app to React 19. In this post, we’ll give an overview of the new features in React 19, and how you can adopt them. - [What’s new in React 19]() - [Improvements in React 19]() - [How to upgrade]() For a list of breaking changes, see the [Upgrade Guide](https://react.dev/blog/2024/04/25/react-19-upgrade-guide). * * * ## What’s new in React 19[Link for What’s new in React 19]() ### Actions[Link for Actions]() A common use case in React apps is to perform a data mutation and then update state in response. For example, when a user submits a form to change their name, you will make an API request, and then handle the response. In the past, you would need to handle pending states, errors, optimistic updates, and sequential requests manually. For example, you could handle the pending and error state in `useState`: ``` // Before Actions function UpdateName({}) { const [name, setName] = useState(""); const [error, setError] = useState(null); const [isPending, setIsPending] = useState(false); const handleSubmit = async () => { setIsPending(true); const error = await updateName(name); setIsPending(false); if (error) { setError(error); return; } redirect("/path"); }; return ( <div> <input value={name} onChange={(event) => setName(event.target.value)} /> <button onClick={handleSubmit} disabled={isPending}> Update </button> {error && <p>{error}</p>} </div> ); } ``` In React 19, we’re adding support for using async functions in transitions to handle pending states, errors, forms, and optimistic updates automatically. For example, you can use `useTransition` to handle the pending state for you: ``` // Using pending state from Actions function UpdateName({}) { const [name, setName] = useState(""); const [error, setError] = useState(null); const [isPending, startTransition] = useTransition(); const handleSubmit = () => { startTransition(async () => { const error = await updateName(name); if (error) { setError(error); return; } redirect("/path"); }) }; return ( <div> <input value={name} onChange={(event) => setName(event.target.value)} /> <button onClick={handleSubmit} disabled={isPending}> Update </button> {error && <p>{error}</p>} </div> ); } ``` The async transition will immediately set the `isPending` state to true, make the async request(s), and switch `isPending` to false after any transitions. This allows you to keep the current UI responsive and interactive while the data is changing. ### Note #### By convention, functions that use async transitions are called “Actions”.[Link for By convention, functions that use async transitions are called “Actions”.]() Actions automatically manage submitting data for you: - **Pending state**: Actions provide a pending state that starts at the beginning of a request and automatically resets when the final state update is committed. - **Optimistic updates**: Actions support the new [`useOptimistic`]() hook so you can show users instant feedback while the requests are submitting. - **Error handling**: Actions provide error handling so you can display Error Boundaries when a request fails, and revert optimistic updates to their original value automatically. - **Forms**: `<form>` elements now support passing functions to the `action` and `formAction` props. Passing functions to the `action` props use Actions by default and reset the form automatically after submission. Building on top of Actions, React 19 introduces [`useOptimistic`]() to manage optimistic updates, and a new hook [`React.useActionState`]() to handle common cases for Actions. In `react-dom` we’re adding [`<form>` Actions]() to manage forms automatically and [`useFormStatus`]() to support the common cases for Actions in forms. In React 19, the above example can be simplified to: ``` // Using <form> Actions and useActionState function ChangeName({ name, setName }) { const [error, submitAction, isPending] = useActionState( async (previousState, formData) => { const error = await updateName(formData.get("name")); if (error) { return error; } redirect("/path"); return null; }, null, ); return ( <form action={submitAction}> <input type="text" name="name" /> <button type="submit" disabled={isPending}>Update</button> {error && <p>{error}</p>} </form> ); } ``` In the next section, we’ll break down each of the new Action features in React 19. ### New hook: `useActionState`[Link for this heading]() To make the common cases easier for Actions, we’ve added a new hook called `useActionState`: ``` const [error, submitAction, isPending] = useActionState( async (previousState, newName) => { const error = await updateName(newName); if (error) { // You can return any result of the action. // Here, we return only the error. return error; } // handle success return null; }, null, ); ``` `useActionState` accepts a function (the “Action”), and returns a wrapped Action to call. This works because Actions compose. When the wrapped Action is called, `useActionState` will return the last result of the Action as `data`, and the pending state of the Action as `pending`. ### Note `React.useActionState` was previously called `ReactDOM.useFormState` in the Canary releases, but we’ve renamed it and deprecated `useFormState`. See [#28491](https://github.com/facebook/react/pull/28491) for more info. For more information, see the docs for [`useActionState`](https://react.dev/reference/react/useActionState). ### React DOM: `<form>` Actions[Link for this heading]() Actions are also integrated with React 19’s new `<form>` features for `react-dom`. We’ve added support for passing functions as the `action` and `formAction` props of `<form>`, `<input>`, and `<button>` elements to automatically submit forms with Actions: ``` <form action={actionFunction}> ``` When a `<form>` Action succeeds, React will automatically reset the form for uncontrolled components. If you need to reset the `<form>` manually, you can call the new `requestFormReset` React DOM API. For more information, see the `react-dom` docs for [`<form>`](https://react.dev/reference/react-dom/components/form), [`<input>`](https://react.dev/reference/react-dom/components/input), and `<button>`. ### React DOM: New hook: `useFormStatus`[Link for this heading]() In design systems, it’s common to write design components that need access to information about the `<form>` they’re in, without drilling props down to the component. This can be done via Context, but to make the common case easier, we’ve added a new hook `useFormStatus`: ``` import {useFormStatus} from 'react-dom'; function DesignButton() { const {pending} = useFormStatus(); return <button type="submit" disabled={pending} /> } ``` `useFormStatus` reads the status of the parent `<form>` as if the form was a Context provider. For more information, see the `react-dom` docs for [`useFormStatus`](https://react.dev/reference/react-dom/hooks/useFormStatus). ### New hook: `useOptimistic`[Link for this heading]() 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: ``` function ChangeName({currentName, onUpdateName}) { const [optimisticName, setOptimisticName] = useOptimistic(currentName); const submitAction = async formData => { const newName = formData.get("name"); setOptimisticName(newName); const updatedName = await updateName(newName); onUpdateName(updatedName); }; return ( <form action={submitAction}> <p>Your name is: {optimisticName}</p> <p> <label>Change Name:</label> <input type="text" name="name" disabled={currentName !== optimisticName} /> </p> </form> ); } ``` The `useOptimistic` hook will immediately render the `optimisticName` while the `updateName` request is in progress. When the update finishes or errors, React will automatically switch back to the `currentName` value. For more information, see the docs for [`useOptimistic`](https://react.dev/reference/react/useOptimistic). ### New API: `use`[Link for this heading]() In React 19 we’re 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 => <p key={comment.id}>{comment}</p>); } function Page({commentsPromise}) { // When `use` suspends in Comments, // this Suspense boundary will be shown. return ( <Suspense fallback={<div>Loading...</div>}> <Comments commentsPromise={commentsPromise} /> </Suspense> ) } ``` ### Note #### `use` does not support promises created in render.[Link for this heading]() If you try to pass a promise created in render to `use`, React will warn: Console A component was suspended by an uncached promise. Creating promises inside a Client Component or hook is not yet supported, except via a Suspense-compatible library or framework. To fix, you need to pass a promise from a suspense powered library or framework that supports caching for promises. In the future we plan to ship features to make it easier to cache promises in render. You can also read context with `use`, allowing you to read Context conditionally such as after early returns: ``` import {use} from 'react'; import ThemeContext from './ThemeContext' function Heading({children}) { if (children == null) { return null; } // This would not work with useContext // because of the early return. const theme = use(ThemeContext); return ( <h1 style={{color: theme.color}}> {children} </h1> ); } ``` The `use` API can only be called in render, similar to hooks. Unlike hooks, `use` can be called conditionally. In the future we plan to support more ways to consume resources in render with `use`. For more information, see the docs for [`use`](https://react.dev/reference/react/use). ## New React DOM Static APIs[Link for New React DOM Static APIs]() We’ve added two new APIs to `react-dom/static` for static site generation: - [`prerender`](https://react.dev/reference/react-dom/static/prerender) - [`prerenderToNodeStream`](https://react.dev/reference/react-dom/static/prerenderToNodeStream) These new APIs improve on `renderToString` by waiting for data to load for static HTML generation. They are designed to work with streaming environments like Node.js Streams and Web Streams. For example, in a Web Stream environment, you can prerender a React tree to static HTML with `prerender`: ``` import { prerender } from 'react-dom/static'; async function handler(request) { const {prelude} = await prerender(<App />, { bootstrapScripts: ['/main.js'] }); return new Response(prelude, { headers: { 'content-type': 'text/html' }, }); } ``` Prerender APIs will wait for all data to load before returning the static HTML stream. Streams can be converted to strings, or sent with a streaming response. They do not support streaming content as it loads, which is supported by the existing [React DOM server rendering APIs](https://react.dev/reference/react-dom/server). For more information, see [React DOM Static APIs](https://react.dev/reference/react-dom/static). ## React Server Components[Link for React Server Components]() ### Server Components[Link for Server Components]() Server Components are a new option that allows rendering components ahead of time, before bundling, in an environment separate from your client application or SSR server. This separate environment is the “server” in React Server Components. Server Components can run once at build time on your CI server, or they can be run for each request using a web server. React 19 includes all of the React Server Components features included from the Canary channel. This means libraries that ship with Server Components can now target React 19 as a peer dependency with a `react-server` [export condition](https://github.com/reactjs/rfcs/blob/main/text/0227-server-module-conventions.md) for use in frameworks that support the [Full-stack React Architecture](https://react.dev/learn/start-a-new-react-project). ### Note #### How do I build support for Server Components?[Link for How do I build support for Server Components?]() While React Server Components in React 19 are stable and will not break between minor versions, the underlying APIs used to implement a React Server Components bundler or framework do not follow semver and may break between minors in React 19.x. To support React Server Components as a bundler or framework, we recommend pinning to a specific React version, or using the Canary release. We will continue working with bundlers and frameworks to stabilize the APIs used to implement React Server Components in the future. For more, see the docs for [React Server Components](https://react.dev/reference/rsc/server-components). ### Server Actions[Link for Server Actions]() Server Actions allow Client Components to call async functions executed on the server. When a Server Action is defined with the `"use server"` directive, your framework will automatically create a reference to the server function, and pass that reference to the Client Component. When that function is called on the client, React will send a request to the server to execute the function, and return the result. ### Note #### There is no directive for Server Components.[Link for There is no directive for Server Components.]() A common misunderstanding is that Server Components are denoted by `"use server"`, but there is no directive for Server Components. The `"use server"` directive is used for Server Actions. For more info, see the docs for [Directives](https://react.dev/reference/rsc/directives). Server Actions can be created in Server Components and passed as props to Client Components, or they can be imported and used in Client Components. For more, see the docs for [React Server Actions](https://react.dev/reference/rsc/server-actions). ## Improvements in React 19[Link for Improvements in React 19]() ### `ref` as a prop[Link for this heading]() Starting in React 19, you can now access `ref` as a prop for function components: ``` function MyInput({placeholder, ref}) { return <input placeholder={placeholder} ref={ref} /> } //... <MyInput ref={ref} /> ``` New function components will no longer need `forwardRef`, and we will be publishing a codemod to automatically update your components to use the new `ref` prop. In future versions we will deprecate and remove `forwardRef`. ### Note `refs` passed to classes are not passed as props since they reference the component instance. ### Diffs for hydration errors[Link for Diffs for hydration errors]() We also improved error reporting for hydration errors in `react-dom`. For example, instead of logging multiple errors in DEV without any information about the mismatch: Console Warning: Text content did not match. Server: “Server” Client: “Client” at span at App Warning: An error occurred during hydration. The server HTML was replaced with client content in &lt;div&gt;. Warning: Text content did not match. Server: “Server” Client: “Client” at span at App Warning: An error occurred during hydration. The server HTML was replaced with client content in &lt;div&gt;. Uncaught Error: Text content does not match server-rendered HTML. at checkForUnmatchedText … We now log a single message with a diff of the mismatch: Console Uncaught Error: Hydration failed because the server rendered HTML didn’t match the client. As a result this tree will be regenerated on the client. This can happen if an SSR-ed Client Component used: - A server/client branch `if (typeof window !== 'undefined')`. - Variable input such as `Date.now()` or `Math.random()` which changes each time it’s called. - Date formatting in a user’s locale which doesn’t match the server. - External changing data without sending a snapshot of it along with the HTML. - Invalid HTML tag nesting. It can also happen if the client has a browser extension installed which messes with the HTML before React loaded. [https://react.dev/link/hydration-mismatch](https://react.dev/link/hydration-mismatch) &lt;App&gt; &lt;span&gt; + Client - Server at throwOnHydrationMismatch … ### `<Context>` as a provider[Link for this heading]() In React 19, you can render `<Context>` as a provider instead of `<Context.Provider>`: ``` const ThemeContext = createContext(''); function App({children}) { return ( <ThemeContext value="dark"> {children} </ThemeContext> ); } ``` New Context providers can use `<Context>` and we will be publishing a codemod to convert existing providers. In future versions we will deprecate `<Context.Provider>`. ### Cleanup functions for refs[Link for Cleanup functions for refs]() We 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 }; }} /> ``` When the component unmounts, React will call the cleanup function returned from the `ref` callback. This works for DOM refs, refs to class components, and `useImperativeHandle`. ### Note Previously, React would call `ref` functions with `null` when unmounting the component. If your `ref` returns a cleanup function, React will now skip this step. In future versions, we will deprecate calling refs with `null` when unmounting components. Due to the introduction of ref cleanup functions, returning anything else from a `ref` callback will now be rejected by TypeScript. The fix is usually to stop using implicit returns, for example: ``` - <div ref={current => (instance = current)} /> + <div ref={current => {instance = current}} /> ``` The original code returned the instance of the `HTMLDivElement` and TypeScript wouldn’t know if this was *supposed* to be a cleanup function or if you didn’t want to return a cleanup function. You can codemod this pattern with [`no-implicit-ref-callback-return`](https://github.com/eps1lon/types-react-codemod/). ### `useDeferredValue` initial value[Link for this heading]() We’ve added an `initialValue` option to `useDeferredValue`: ``` function Search({deferredValue}) { // On initial render the value is ''. // Then a re-render is scheduled with the deferredValue. const value = useDeferredValue(deferredValue, ''); return ( <Results query={value} /> ); } ``` When initialValue is provided, `useDeferredValue` will return it as `value` for the initial render of the component, and schedules a re-render in the background with the deferredValue returned. For more, see [`useDeferredValue`](https://react.dev/reference/react/useDeferredValue). ### Support for Document Metadata[Link for Support for Document Metadata]() In HTML, document metadata tags like `<title>`, `<link>`, and `<meta>` are reserved for placement in the `<head>` section of the document. In React, the component that decides what metadata is appropriate for the app may be very far from the place where you render the `<head>` or React does not render the `<head>` at all. In the past, these elements would need to be inserted manually in an effect, or by libraries like [`react-helmet`](https://github.com/nfl/react-helmet), and required careful handling when server rendering a React application. In React 19, we’re adding support for rendering document metadata tags in components natively: ``` function BlogPost({post}) { return ( <article> <h1>{post.title}</h1> <title>{post.title}</title> <meta name="author" content="Josh" /> <link rel="author" href="https://twitter.com/joshcstory/" /> <meta name="keywords" content={post.keywords} /> <p> Eee equals em-see-squared... </p> </article> ); } ``` When React renders this component, it will see the `<title>` `<link>` and `<meta>` tags, and automatically hoist them to the `<head>` section of document. By supporting these metadata tags natively, we’re able to ensure they work with client-only apps, streaming SSR, and Server Components. ### Note #### You may still want a Metadata library[Link for You may still want a Metadata library]() For simple use cases, rendering Document Metadata as tags may be suitable, but libraries can offer more powerful features like overriding generic metadata with specific metadata based on the current route. These features make it easier for frameworks and libraries like [`react-helmet`](https://github.com/nfl/react-helmet) to support metadata tags, rather than replace them. For more info, see the docs for [`<title>`](https://react.dev/reference/react-dom/components/title), [`<link>`](https://react.dev/reference/react-dom/components/link), and [`<meta>`](https://react.dev/reference/react-dom/components/meta). ### Support for stylesheets[Link for Support for stylesheets]() Stylesheets, both externally linked (`<link rel="stylesheet" href="...">`) and inline (`<style>...</style>`), require careful positioning in the DOM due to style precedence rules. Building a stylesheet capability that allows for composability within components is hard, so users often end up either loading all of their styles far from the components that may depend on them, or they use a style library which encapsulates this complexity. In React 19, we’re addressing this complexity and providing even deeper integration into Concurrent Rendering on the Client and Streaming Rendering on the Server with built in support for stylesheets. If you tell React the `precedence` of your stylesheet it will manage the insertion order of the stylesheet in the DOM and ensure that the stylesheet (if external) is loaded before revealing content that depends on those style rules. ``` 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> ) } ``` During Server Side Rendering React will include the stylesheet in the `<head>`, which ensures that the browser will not paint until it has loaded. If the stylesheet is discovered late after we’ve already started streaming, React will ensure that the stylesheet is inserted into the `<head>` on the client before revealing the content of a Suspense boundary that depends on that stylesheet. During Client Side Rendering React will wait for newly rendered stylesheets to load before committing the render. If you render this component from multiple places within your application React will only include the stylesheet once in the document: ``` function App() { return <> <ComponentOne /> ... <ComponentOne /> // won't lead to a duplicate stylesheet link in the DOM </> } ``` For users accustomed to loading stylesheets manually this is an opportunity to locate those stylesheets alongside the components that depend on them allowing for better local reasoning and an easier time ensuring you only load the stylesheets that you actually depend on. Style libraries and style integrations with bundlers can also adopt this new capability so even if you don’t directly render your own stylesheets, you can still benefit as your tools are upgraded to use this feature. For more details, read the docs for [`<link>`](https://react.dev/reference/react-dom/components/link) and [`<style>`](https://react.dev/reference/react-dom/components/style). ### Support for async scripts[Link for Support for async scripts]() In HTML normal scripts (`<script src="...">`) and deferred scripts (`<script defer="" src="...">`) load in document order which makes rendering these kinds of scripts deep within your component tree challenging. Async scripts (`<script async="" src="...">`) however will load in arbitrary order. In React 19 we’ve included better support for async scripts by allowing you to render them anywhere in your component tree, inside the components that actually depend on the script, without having to manage relocating and deduplicating script instances. ``` function MyComponent() { return ( <div> <script async={true} src="..." /> Hello World </div> ) } function App() { <html> <body> <MyComponent> ... <MyComponent> // won't lead to duplicate script in the DOM </body> </html> } ``` In all rendering environments, async scripts will be deduplicated so that React will only load and execute the script once even if it is rendered by multiple different components. In Server Side Rendering, async scripts will be included in the `<head>` and prioritized behind more critical resources that block paint such as stylesheets, fonts, and image preloads. For more details, read the docs for [`<script>`](https://react.dev/reference/react-dom/components/script). ### Support for preloading resources[Link for Support for preloading resources]() During initial document load and on client side updates, telling the Browser about resources that it will likely need to load as early as possible can have a dramatic effect on page performance. React 19 includes a number of new APIs for loading and preloading Browser resources to make it as easy as possible to build great experiences that aren’t held back by inefficient 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> ``` These APIs can be used to optimize initial page loads by moving discovery of additional resources like fonts out of stylesheet loading. They can also make client updates faster by prefetching a list of resources used by an anticipated navigation and then eagerly preloading those resources on click or even on hover. For more details see [Resource Preloading APIs](https://react.dev/reference/react-dom). ### Compatibility with third-party scripts and extensions[Link for Compatibility with third-party scripts and extensions]() We’ve improved hydration to account for third-party scripts and browser extensions. When hydrating, if an element that renders on the client doesn’t match the element found in the HTML from the server, React will force a client re-render to fix up the content. Previously, if an element was inserted by third-party scripts or browser extensions, it would trigger a mismatch error and client render. In React 19, unexpected tags in the `<head>` and `<body>` will be skipped over, avoiding the mismatch errors. If React needs to re-render the entire document due to an unrelated hydration mismatch, it will leave in place stylesheets inserted by third-party scripts and browser extensions. ### Better error reporting[Link for Better error reporting]() We improved error handling in React 19 to remove duplication and provide options for handling caught and uncaught errors. For example, when there’s an error in render caught by an Error Boundary, previously React would throw the error twice (once for the original error, then again after failing to automatically recover), and then call `console.error` with info about where the error occurred. This resulted in three errors for every caught error: Console Uncaught Error: hit at Throws at renderWithHooks … Uncaught Error: hit &lt;-- Duplicate at Throws at renderWithHooks … The above error occurred in the Throws component: at Throws at ErrorBoundary at App React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary. In React 19, we log a single error with all the error information included: Console Error: hit at Throws at renderWithHooks … The above error occurred in the Throws component: at Throws at ErrorBoundary at App React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary. at ErrorBoundary at App Additionally, we’ve added two new root options to complement `onRecoverableError`: - `onCaughtError`: called when React catches an error in an Error Boundary. - `onUncaughtError`: called when an error is thrown and not caught by an Error Boundary. - `onRecoverableError`: called when an error is thrown and automatically recovered. For more info and examples, see the docs for [`createRoot`](https://react.dev/reference/react-dom/client/createRoot) and [`hydrateRoot`](https://react.dev/reference/react-dom/client/hydrateRoot). ### Support for Custom Elements[Link for Support for Custom Elements]() React 19 adds full support for custom elements and passes all tests on [Custom Elements Everywhere](https://custom-elements-everywhere.com/). In past versions, using Custom Elements in React has been difficult because React treated unrecognized props as attributes rather than properties. In React 19, we’ve added support for properties that works on the client and during SSR with the following strategy: - **Server Side Rendering**: props passed to a custom element will render as attributes if their type is a primitive value like `string`, `number`, or the value is `true`. Props with non-primitive types like `object`, `symbol`, `function`, or value `false` will be omitted. - **Client Side Rendering**: props that match a property on the Custom Element instance will be assigned as properties, otherwise they will be assigned as attributes. Thanks to [Joey Arhar](https://github.com/josepharhar) for driving the design and implementation of Custom Element support in React. #### How to upgrade[Link for How to upgrade]() See the [React 19 Upgrade Guide](https://react.dev/blog/2024/04/25/react-19-upgrade-guide) for step-by-step instructions and a full list of breaking and notable changes. *Note: this post was originally published 04/25/2024 and has been updated to 12/05/2024 with the stable release.* [PreviousBlog](https://react.dev/blog) [NextReact Compiler Beta Release and Roadmap](https://react.dev/blog/2024/10/21/react-compiler-beta-release)
https://react.dev/learn/installation
[Learn React](https://react.dev/learn) # Installation[Link for this heading]() React has been designed from the start for gradual adoption. You can use as little or as much React as you need. Whether you want to get a taste of React, add some interactivity to an HTML page, or start a complex React-powered app, this section will help you get started. ### In this chapter - [How to start a new React project](https://react.dev/learn/start-a-new-react-project) - [How to add React to an existing project](https://react.dev/learn/add-react-to-an-existing-project) - [How to set up your editor](https://react.dev/learn/editor-setup) - [How to install React Developer Tools](https://react.dev/learn/react-developer-tools) ## Try React[Link for Try React]() You don’t need to install anything to play with React. Try editing this sandbox! App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` function Greeting({ name }) { return <h1>Hello, {name}</h1>; } export default function App() { return <Greeting name="world" /> } ``` You can edit it directly or open it in a new tab by pressing the “Fork” button in the upper right corner. Most pages in the React documentation contain sandboxes like this. Outside of the React documentation, there are many online sandboxes that support React: for example, [CodeSandbox](https://codesandbox.io/s/new), [StackBlitz](https://stackblitz.com/fork/react), or [CodePen.](https://codepen.io/pen?template=QWYVwWN) ### Try React locally[Link for Try React locally]() To try React locally on your computer, [download this HTML page.](https://gist.githubusercontent.com/gaearon/0275b1e1518599bbeafcde4722e79ed1/raw/db72dcbf3384ee1708c4a07d3be79860db04bff0/example.html) Open it in your editor and in your browser! ## Start a new React project[Link for Start a new React project]() If you want to build an app or a website fully with React, [start a new React project.](https://react.dev/learn/start-a-new-react-project) ## Add React to an existing project[Link for Add React to an existing project]() If want to try using React in your existing app or a website, [add React to an existing project.](https://react.dev/learn/add-react-to-an-existing-project) ## Next steps[Link for Next steps]() Head to the [Quick Start](https://react.dev/learn) guide for a tour of the most important React concepts you will encounter every day. [PreviousThinking in React](https://react.dev/learn/thinking-in-react) [NextStart a New React Project](https://react.dev/learn/start-a-new-react-project)
https://react.dev/learn/adding-interactivity
[Learn React](https://react.dev/learn) # Adding Interactivity[Link for this heading]() Some things on the screen update in response to user input. For example, clicking an image gallery switches the active image. In React, data that changes over time is called *state.* You can add state to any component, and update it as needed. In this chapter, you’ll learn how to write components that handle interactions, update their state, and display different output over time. ### In this chapter - [How to handle user-initiated events](https://react.dev/learn/responding-to-events) - [How to make components “remember” information with state](https://react.dev/learn/state-a-components-memory) - [How React updates the UI in two phases](https://react.dev/learn/render-and-commit) - [Why state doesn’t update right after you change it](https://react.dev/learn/state-as-a-snapshot) - [How to queue multiple state updates](https://react.dev/learn/queueing-a-series-of-state-updates) - [How to update an object in state](https://react.dev/learn/updating-objects-in-state) - [How to update an array in state](https://react.dev/learn/updating-arrays-in-state) ## Responding to events[Link for Responding to events]() React lets you add *event handlers* to your JSX. Event handlers are your own functions that will be triggered in response to user interactions like clicking, hovering, focusing on form inputs, and so on. Built-in components like `<button>` only support built-in browser events like `onClick`. However, you can also create your own components, and give their event handler props any application-specific names that you like. App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` export default function App() { return ( <Toolbar onPlayMovie={() => alert('Playing!')} onUploadImage={() => alert('Uploading!')} /> ); } function Toolbar({ onPlayMovie, onUploadImage }) { return ( <div> <Button onClick={onPlayMovie}> Play Movie </Button> <Button onClick={onUploadImage}> Upload Image </Button> </div> ); } function Button({ onClick, children }) { return ( <button onClick={onClick}> {children} </button> ); } ``` Show more ## Ready to learn this topic? Read [**Responding to Events**](https://react.dev/learn/responding-to-events) to learn how to add event handlers. [Read More](https://react.dev/learn/responding-to-events) * * * ## State: a component’s memory[Link for State: a component’s memory]() Components often need to change what’s on the screen as a result of an interaction. Typing into the form should update the input field, clicking “next” on an image carousel should change which image is displayed, clicking “buy” puts a product in the shopping cart. Components need to “remember” things: the current input value, the current image, the shopping cart. In React, this kind of component-specific memory is called *state.* You can add state to a component with a [`useState`](https://react.dev/reference/react/useState) Hook. *Hooks* are special functions that let your components use React features (state is one of those features). The `useState` Hook lets you declare a state variable. It takes the initial state and returns a pair of values: the current state, and a state setter function that lets you update it. ``` const [index, setIndex] = useState(0); const [showMore, setShowMore] = useState(false); ``` Here is how an image gallery uses and updates state on click: App.jsdata.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` import { useState } from 'react'; import { sculptureList } from './data.js'; export default function Gallery() { const [index, setIndex] = useState(0); const [showMore, setShowMore] = useState(false); const hasNext = index < sculptureList.length - 1; function handleNextClick() { if (hasNext) { setIndex(index + 1); } else { setIndex(0); } } function handleMoreClick() { setShowMore(!showMore); } let sculpture = sculptureList[index]; return ( <> <button onClick={handleNextClick}> Next </button> <h2> <i>{sculpture.name} </i> by {sculpture.artist} </h2> <h3> ({index + 1} of {sculptureList.length}) </h3> <button onClick={handleMoreClick}> {showMore ? 'Hide' : 'Show'} details </button> {showMore && <p>{sculpture.description}</p>} <img src={sculpture.url} alt={sculpture.alt} /> </> ); } ``` Show more ## Ready to learn this topic? Read [**State: A Component’s Memory**](https://react.dev/learn/state-a-components-memory) to learn how to remember a value and update it on interaction. [Read More](https://react.dev/learn/state-a-components-memory) * * * ## Render and commit[Link for Render and commit]() Before your components are displayed on the screen, they must be rendered by React. Understanding the steps in this process will help you think about how your code executes and explain its behavior. Imagine that your components are cooks in the kitchen, assembling tasty dishes from ingredients. In this scenario, React is the waiter who puts in requests from customers and brings them their orders. This process of requesting and serving UI has three steps: 1. **Triggering** a render (delivering the diner’s order to the kitchen) 2. **Rendering** the component (preparing the order in the kitchen) 3. **Committing** to the DOM (placing the order on the table) <!--THE END--> 1. ![React as a server in a restaurant, fetching orders from the users and delivering them to the Component Kitchen.](/images/docs/illustrations/i_render-and-commit1.png) Trigger 2. ![The Card Chef gives React a fresh Card component.](/images/docs/illustrations/i_render-and-commit2.png) Render 3. ![React delivers the Card to the user at their table.](/images/docs/illustrations/i_render-and-commit3.png) Commit Illustrated by [Rachel Lee Nabors](https://nearestnabors.com/) ## Ready to learn this topic? Read [**Render and Commit**](https://react.dev/learn/render-and-commit) to learn the lifecycle of a UI update. [Read More](https://react.dev/learn/render-and-commit) * * * ## State as a snapshot[Link for State as a snapshot]() Unlike regular JavaScript variables, React state behaves more like a snapshot. Setting it does not change the state variable you already have, but instead triggers a re-render. This can be surprising at first! ``` console.log(count); // 0 setCount(count + 1); // Request a re-render with 1 console.log(count); // Still 0! ``` This behavior helps you avoid subtle bugs. Here is a little chat app. Try to guess what happens if you press “Send” first and *then* change the recipient to Bob. Whose name will appear in the `alert` five seconds later? App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` import { useState } from 'react'; export default function Form() { const [to, setTo] = useState('Alice'); const [message, setMessage] = useState('Hello'); function handleSubmit(e) { e.preventDefault(); setTimeout(() => { alert(`You said ${message} to ${to}`); }, 5000); } return ( <form onSubmit={handleSubmit}> <label> To:{' '} <select value={to} onChange={e => setTo(e.target.value)}> <option value="Alice">Alice</option> <option value="Bob">Bob</option> </select> </label> <textarea placeholder="Message" value={message} onChange={e => setMessage(e.target.value)} /> <button type="submit">Send</button> </form> ); } ``` Show more ## Ready to learn this topic? Read [**State as a Snapshot**](https://react.dev/learn/state-as-a-snapshot) to learn why state appears “fixed” and unchanging inside the event handlers. [Read More](https://react.dev/learn/state-as-a-snapshot) * * * ## Queueing a series of state updates[Link for Queueing a series of state updates]() This component is buggy: clicking “+3” increments the score only once. App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` import { useState } from 'react'; export default function Counter() { const [score, setScore] = useState(0); function increment() { setScore(score + 1); } return ( <> <button onClick={() => increment()}>+1</button> <button onClick={() => { increment(); increment(); increment(); }}>+3</button> <h1>Score: {score}</h1> </> ) } ``` Show more [State as a Snapshot](https://react.dev/learn/state-as-a-snapshot) explains why this is happening. Setting state requests a new re-render, but does not change it in the already running code. So `score` continues to be `0` right after you call `setScore(score + 1)`. ``` console.log(score); // 0 setScore(score + 1); // setScore(0 + 1); console.log(score); // 0 setScore(score + 1); // setScore(0 + 1); console.log(score); // 0 setScore(score + 1); // setScore(0 + 1); console.log(score); // 0 ``` You can fix this by passing an *updater function* when setting state. Notice how replacing `setScore(score + 1)` with `setScore(s => s + 1)` fixes the “+3” button. This lets you queue multiple state updates. App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` import { useState } from 'react'; export default function Counter() { const [score, setScore] = useState(0); function increment() { setScore(s => s + 1); } return ( <> <button onClick={() => increment()}>+1</button> <button onClick={() => { increment(); increment(); increment(); }}>+3</button> <h1>Score: {score}</h1> </> ) } ``` Show more ## Ready to learn this topic? Read [**Queueing a Series of State Updates**](https://react.dev/learn/queueing-a-series-of-state-updates) to learn how to queue a sequence of state updates. [Read More](https://react.dev/learn/queueing-a-series-of-state-updates) * * * ## Updating objects in state[Link for Updating objects in state]() State can hold any kind of JavaScript value, including objects. But you shouldn’t change objects and arrays that you hold in the React state directly. Instead, when you want to update an object and array, you need to create a new one (or make a copy of an existing one), and then update the state to use that copy. Usually, you will use the `...` spread syntax to copy objects and arrays that you want to change. For example, updating a nested object could look like this: App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` import { useState } from 'react'; export default function Form() { const [person, setPerson] = useState({ name: 'Niki de Saint Phalle', artwork: { title: 'Blue Nana', city: 'Hamburg', image: 'https://i.imgur.com/Sd1AgUOm.jpg', } }); function handleNameChange(e) { setPerson({ ...person, name: e.target.value }); } function handleTitleChange(e) { setPerson({ ...person, artwork: { ...person.artwork, title: e.target.value } }); } function handleCityChange(e) { setPerson({ ...person, artwork: { ...person.artwork, city: e.target.value } }); } function handleImageChange(e) { setPerson({ ...person, artwork: { ...person.artwork, image: e.target.value } }); } return ( <> <label> Name: <input value={person.name} onChange={handleNameChange} /> </label> <label> Title: <input value={person.artwork.title} onChange={handleTitleChange} /> </label> <label> City: <input value={person.artwork.city} onChange={handleCityChange} /> </label> <label> Image: <input value={person.artwork.image} onChange={handleImageChange} /> </label> <p> <i>{person.artwork.title}</i> {' by '} {person.name} <br /> (located in {person.artwork.city}) </p> <img src={person.artwork.image} alt={person.artwork.title} /> </> ); } ``` Show more If copying objects in code gets tedious, you can use a library like [Immer](https://github.com/immerjs/use-immer) to reduce repetitive code: package.jsonApp.js package.json Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` { "dependencies": { "immer": "1.7.3", "react": "latest", "react-dom": "latest", "react-scripts": "latest", "use-immer": "0.5.1" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" }, "devDependencies": {} } ``` ## Ready to learn this topic? Read [**Updating Objects in State**](https://react.dev/learn/updating-objects-in-state) to learn how to update objects correctly. [Read More](https://react.dev/learn/updating-objects-in-state) * * * ## Updating arrays in state[Link for Updating arrays in state]() Arrays are another type of mutable JavaScript objects you can store in state and should treat as read-only. Just like with objects, when you want to update an array stored in state, you need to create a new one (or make a copy of an existing one), and then set state to use the new array: App.js App.js Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` import { useState } from 'react'; const initialList = [ { id: 0, title: 'Big Bellies', seen: false }, { id: 1, title: 'Lunar Landscape', seen: false }, { id: 2, title: 'Terracotta Army', seen: true }, ]; export default function BucketList() { const [list, setList] = useState( initialList ); function handleToggle(artworkId, nextSeen) { setList(list.map(artwork => { if (artwork.id === artworkId) { return { ...artwork, seen: nextSeen }; } else { return artwork; } })); } return ( <> <h1>Art Bucket List</h1> <h2>My list of art to see:</h2> <ItemList artworks={list} onToggle={handleToggle} /> </> ); } function ItemList({ artworks, onToggle }) { return ( <ul> {artworks.map(artwork => ( <li key={artwork.id}> <label> <input type="checkbox" checked={artwork.seen} onChange={e => { onToggle( artwork.id, e.target.checked ); }} /> {artwork.title} </label> </li> ))} </ul> ); } ``` Show more If copying arrays in code gets tedious, you can use a library like [Immer](https://github.com/immerjs/use-immer) to reduce repetitive code: package.jsonApp.js package.json Reset[Fork](https://codesandbox.io/api/v1/sandboxes/define?undefined&environment=create-react-app "Open in CodeSandbox") ``` { "dependencies": { "immer": "1.7.3", "react": "latest", "react-dom": "latest", "react-scripts": "latest", "use-immer": "0.5.1" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" }, "devDependencies": {} } ``` ## Ready to learn this topic? Read [**Updating Arrays in State**](https://react.dev/learn/updating-arrays-in-state) to learn how to update arrays correctly. [Read More](https://react.dev/learn/updating-arrays-in-state) * * * ## What’s next?[Link for What’s next?]() Head over to [Responding to Events](https://react.dev/learn/responding-to-events) to start reading this chapter page by page! Or, if you’re already familiar with these topics, why not read about [Managing State](https://react.dev/learn/managing-state)? [PreviousYour UI as a Tree](https://react.dev/learn/understanding-your-ui-as-a-tree) [NextResponding to Events](https://react.dev/learn/responding-to-events)

No dataset card yet

Downloads last month
9