/* * Copyright (c) Facebook, Inc. and its affiliates. */ import {createContext, useState, useContext, Suspense} from 'react'; import ButtonLink from '../ButtonLink'; import {IconRestart} from '../Icon/IconRestart'; import {Logo} from 'components/Logo'; import Link from 'components/MDX/Link'; import CodeBlock from 'components/MDX/CodeBlock'; import cn from 'classnames'; export function HomeContent() { return ( <>

React

The library for web and native user interfaces

Learn React API Reference

Create user interfaces from components

React lets you build user interfaces out of individual pieces called components. Create your own React components like a button, a panel, or an avatar. Then combine them into entire screens, pages, and apps.

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 something conditionally? Use an if statement. Need to display a list? Use a for loop or array{' '} map(). Learning React is learning programming.

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.

Go full-stack with a framework

React is a library. It lets you put components together, but it doesn’t prescribe solutions for routing and data fetching. To get the most out of React, we recommend a React framework like{' '} Next.js,{' '} Remix, and{' '} Expo. Frameworks let you create full-stack apps with very little configuration.

To frameworks, React is more than a library—React is an architecture. React provides a unified programming model that spans across client and server so that you can use both of them for what they are best at.

Make the best use of the platform

Web users expect pages to load fast. React can render into an HTML stream on the server, gradually revealing more content even before React itself has loaded on the client. React relies on modern web standards to keep the page responsive even during rendering.


Mobile app users expect native look-and-feel. With{' '} React Native, you can create Android and iOS apps with React. These user interfaces can feel truly native because they are truly native. Your React components render real Android and iOS views natively provided by the platform.

Use as little or as much React as you need

Many teams build their entire user interface with React. For example, the web experiences of Facebook, Instagram, TikTok, Twitter, Airbnb, Spotify, Trello, and The New York Times {' '} are fully powered by React.

Stability without stagnation

React approaches changes with care. Every React commit is tested on business-critical surfaces with hundreds of millions of users. When an API is deprecated, we add warnings and publish automatic scripts to assist with the migration. The 100,000 React components in the Meta codebase help validate every migration strategy. The React team is also always researching how to improve React. React has a high bar for taking an idea from research to production. Only proven approaches become part of React.
Learn about our latest research

Q1 2022

React v18

Lorem ipsum dolor

Q4 2020

Server components

Lorem ipsum dolor

Q4 2020

React v17

Lorem ipsum dolor

Q1 2019

Hooks

Lorem ipsum dolor

Q4 2017

React v16

Lorem ipsum dolor

Stability without stagnation

React approaches changes with care. Every React commit is tested on business-critical surfaces with hundreds of millions of users.

Illustration goes here

React homepage section header

Illustration goes here

Use as little or as much
React as you need

Many teams build their entire user interface with React.

Stability without stagnation

React approaches changes with care. Every React commit is tested on business-critical surfaces with hundreds of millions of users.

Illustration goes here
Illustration goes here

Let a framework take care of the rest

React is a library. It lets you create components and put them together, but it doesn't prescribe solutions for routing and data fetching.

Welcome to the React community

Get started today.

Welcome to the React community

Get started today.

); } function Example1() { return (

Comment.js

{`function Comment({ comment }) { return (

{comment.text}

); } `}
); } const PostContext = createContext(null); const author = { name: 'First name', image: null, }; function Example2() { const [comments, setComments] = useState([ { id: 0, text: 'The quick brown fox jumps over the lazy dog', postedAt: '10m ago', author, }, { id: 1, text: 'The quick brown fox jumps over the lazy dog', postedAt: '4m ago', author, }, { id: 2, text: 'The quick brown fox jumps over the lazy dog', postedAt: '2m ago', author, }, ]); function handleAddComment(text) { setComments((c) => [ ...c, { id: c.length, text, postedAt: 'just now', author, }, ]); } return (

CommentList.js

{`function CommentList({ comments }) { let heading = 'Be the first to comment'; if (comments.length > 0) { heading = comments.length + ' Comments'; } return (

{heading}

{comments.map(comment => )}
); }`}
); } function Example3() { const [postPromise, setPostPromise] = useState(null); const [commentsPromise, setCommentsPromise] = useState(null); const [comments, setComments] = useState([ { id: 0, text: 'fika :D', postedAt: '1h ago', author: { name: 'Luna', image: { url: 'https://i.imgur.com/B3E9zDz.jpg', }, }, }, { id: 1, text: `ok, I have to ask. What is FIKA?`, postedAt: '12m ago', author: { name: 'Samuel', image: { url: 'https://i.imgur.com/OUkVY2C.jpg', }, }, }, { id: 2, text: `It's a thing the core team used to do, I believe (never been to one). ` + `Basically grab a drink and/or snack and just chill for a bit together`, postedAt: '7m ago', author: { name: 'Lauren', image: { url: 'https://i.imgur.com/8ayW9oH.jpg', }, }, }, { id: 3, text: `When I ask to get cofee, I really mean "fika".`, postedAt: '4m ago', author: { name: 'Sebastian', image: { url: 'https://i.imgur.com/FX7DZbQ.jpg', }, }, }, { id: 4, text: `There's no english word for it.`, postedAt: '4m ago', author: { name: 'Sebastian', image: { url: 'https://i.imgur.com/FX7DZbQ.jpg', }, }, }, { id: 5, text: `we need more sweets to go with the coffee!`, postedAt: '2m ago', author: { name: 'Yuzhi', image: { url: 'https://i.imgur.com/jxLrU8B.jpg', }, }, }, ]); function handleAddComment(text) { setComments((c) => [ ...c, { id: c.length, text, postedAt: 'just now', author, }, ]); } return (

PostPage.js

{`async function PostPage({ slug }) { const post = await db.findPost({ slug }); return ( }> ); } async function PostComments({ postId }) { const comments = await db.findComments({ postId }); return ( <> ); }`}
); } function ExamplePanel({children, noPadding, noShadow, height}) { return (
{children}
); } function BrowserChrome({children, setPostPromise, setCommentsPromise}) { function handleRestart() { const postPromise = new Promise((resolve) => { setTimeout(() => { postPromise._resolved = true; resolve(); }, 200); }); const commentsPromise = new Promise((resolve) => { setTimeout(() => { commentsPromise._resolved = true; resolve(); }, 2200); }); setPostPromise(postPromise); setCommentsPromise(commentsPromise); } return (
example.com /posts/its-fika-time
{children}
); } function PostPage({post, postPromise, commentsPromise}) { if (postPromise && !postPromise._resolved) { throw postPromise; } return ( }> ); } function CommentsSkeleton() { return (
); } function PostComments({post, commentsPromise}) { if (commentsPromise && !commentsPromise._resolved) { throw commentsPromise; } return ( ); } function CommentList({comments, children}) { let headingText = 'Be the first to comment'; if (comments.length > 0) { headingText = comments.length + ' Comments'; } return (
{headingText} {comments.map((comment) => ( ))} {children}
); } function PostCover({imageUrl, children}) { return ( <>
Cover image
{children}
); } function Heading({children}) { return (

{children}

); } function AddComment() { const {currentUser, onAddComment} = useContext(PostContext); return (

{ e.preventDefault(); const formData = new FormData(e.target); const json = Object.fromEntries(formData.entries()); onAddComment(json.text); e.target.reset(); }}>
); } function Comment({comment}) { const {author} = comment; return (
{author.name} {comment.text}
); } function Stack({children, gap}) { return (
{children}
); } function Code({children}) { return ( {children} ); } function Row({children}) { return
{children}
; } function ExampleLink({children}) { return (
{children}
); } function Avatar({user}) { return (
{user.image ? null : }
); } function AvatarPlaceholder() { return ( ); } function Timestamp({time}) { return ( {time} ); }