diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index de2bfc362..ab8a7d4fe 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -3,5 +3,5 @@ contact_links: url: https://github.com/react/react/issues/new/choose about: This issue tracker is not for bugs in React. Please file React issues here. - name: 🤔 Questions and Help - url: https://reactjs.org/community/support.html + url: https://react.dev/community about: This issue tracker is not for support questions. Please refer to the React community's help and discussion forums. diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index 83e7f2e8a..1620c50f6 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -18,7 +18,7 @@ jobs: - name: Set up node uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: '24.x' cache: yarn cache-dependency-path: yarn.lock @@ -26,7 +26,7 @@ jobs: uses: actions/cache@v4 with: path: '**/node_modules' - key: node_modules-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }} + key: node_modules-24-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }} - name: Install deps run: yarn install --frozen-lockfile diff --git a/.github/workflows/site_lint.yml b/.github/workflows/site_lint.yml index 81a04601c..ef43b2c8f 100644 --- a/.github/workflows/site_lint.yml +++ b/.github/workflows/site_lint.yml @@ -13,14 +13,14 @@ jobs: lint: runs-on: ubuntu-latest - name: Lint on node 20.x and ubuntu-latest + name: Lint on node 24.x and ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Use Node.js 20.x + - name: Use Node.js 24.x uses: actions/setup-node@v4 with: - node-version: 20.x + node-version: 24.x cache: yarn cache-dependency-path: yarn.lock @@ -28,7 +28,7 @@ jobs: uses: actions/cache@v4 with: path: '**/node_modules' - key: node_modules-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }} + key: node_modules-24-${{ runner.arch }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }} - name: Install deps run: yarn install --frozen-lockfile diff --git a/CLAUDE.md b/CLAUDE.md index 3a081e6d5..3943097cc 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -4,7 +4,7 @@ This file provides guidance to Claude Code when working with this repository. ## Project Overview -This is the React documentation website (react.dev), built with Next.js 15.1.11 and React 19. Documentation is written in MDX format. +This is the React documentation website (react.dev), built with Next.js 15.1.12 and React 19. Documentation is written in MDX format. ## Development Commands @@ -47,6 +47,6 @@ When editing files in `src/content/`, the appropriate skill will be auto-suggest For MDX components (DeepDive, Pitfall, Note, etc.), invoke `/docs-components`. For Sandpack code examples, invoke `/docs-sandpack`. -See `.claude/docs/react-docs-patterns.md` for comprehensive style guidelines. +See `.claude/skills/` for comprehensive style guidelines. Prettier is used for formatting (config in `.prettierrc`). diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index f049d4c53..14e553ed8 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -55,8 +55,9 @@ a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at . All -complaints will be reviewed and investigated and will result in a response that +reported by following the +[reporting instructions in React's Code of Conduct](https://github.com/react/react/blob/main/CODE_OF_CONDUCT.md#enforcement). +All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4c7e5ec74..b6306c145 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,9 +4,7 @@ Thank you for your interest in contributing to the React Docs! ## Code of Conduct -Facebook has adopted a Code of Conduct that we expect project -participants to adhere to. Please [read the full text](https://code.facebook.com/codeofconduct) -so that you can understand what actions will and will not be tolerated. +We expect all project participants to follow our [Code of Conduct](./CODE_OF_CONDUCT.md). ## Technical Writing Tips @@ -38,41 +36,9 @@ Ignore this if you're specifically describing `createElement`. Ignore this if you're specifically writing about ES5. -#### Don't use ES6 features when equivalent ES5 features have no downsides. +#### Prefer readable syntax. -Remember that ES6 is still new to a lot of people. While we use it in many places (`const` / `let`, classes, arrow functions), if the equivalent ES5 code is just as straightforward and readable, consider using it. - -In particular, you should prefer named `function` declarations over `const myFunction = () => ...` arrows for top-level functions. However, you *should* use arrow functions where they provide a tangible improvement (such as preserving `this` context inside a component). Consider both sides of the tradeoff when deciding whether to use a new feature. - -#### Don't use features that aren't standardized yet. - -For example, **don't** write this: - -```js -class MyComponent extends React.Component { - state = {value: ''}; - handleChange = (e) => { - this.setState({value: e.target.value}); - }; -} -``` - -Instead, **do** write this: - -```js -class MyComponent extends React.Component { - constructor(props) { - super(props); - this.handleChange = this.handleChange.bind(this); - this.state = {value: ''}; - } - handleChange(e) { - this.setState({value: e.target.value}); - } -} -``` - -Ignore this rule if you're specifically describing an experimental proposal. Make sure to mention its experimental nature in the code and in the surrounding text. +Choose syntax that makes each example easier to follow. Prefer named `function` declarations over `const myFunction = () => ...` arrows for top-level functions. Use arrow functions when they make callbacks easier to read. In class components, arrow functions can also preserve the component's `this` value. ### Style diff --git a/README.md b/README.md index 1c4a16438..2e8c64cac 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This repo contains the source code and documentation powering [bn.react.dev](https://bn.react.dev/). +React is a project of the [React Foundation](https://react.foundation/), hosted by the [Linux Foundation](https://www.linuxfoundation.org/). + ## Getting started ### Join the Bengali discord community @@ -10,14 +12,19 @@ Hi dev, We are Bengali React doc translation community welcome you to join the d ### Prerequisites 1. Git -1. Node: any version starting with v16.8.0 or greater -1. Yarn: See [Yarn website for installation instructions](https://yarnpkg.com/lang/en/docs/install/) +1. Node: v24 or greater +1. Yarn Classic: See [Yarn website for installation instructions](https://classic.yarnpkg.com/en/docs/install/) 1. A fork of the repo (for any contributions) 1. A clone of the [bn.react.dev repo](https://github.com/reactjs/bn.react.dev) on your local machine ### Installation +<<<<<<< HEAD 1. `cd bn.react.dev` to go into the project root +======= +1. `cd react.dev` to go into the project root +2. `git remote add my-fork-name https://github.com/YOUR_USERNAME/react.dev.git` to add your fork as a remote. Replace `YOUR_USERNAME` with your GitHub username. You only need to do this once. +>>>>>>> 15653c0f9b95d6c4845e614e5bcc94c7ee2128f6 3. `yarn` to install the website's npm dependencies ### Running locally @@ -42,8 +49,8 @@ The documentation is divided into several sections with a different tone and pur 1. Follow the ["Running locally"](#running-locally) instructions 1. Save the files and check in the browser 1. Changes to React components in `src` will hot-reload - 1. Changes to markdown files in `content` will hot-reload - 1. If working with plugins, you may need to remove the `.cache` directory and restart the server + 1. Changes to markdown files in `src/content` will hot-reload + 1. If working with plugins, you may need to remove the `node_modules/.cache/react-docs-mdx` directory and restart the server ### Test the change @@ -60,7 +67,11 @@ The documentation is divided into several sections with a different tone and pur ## Translation +<<<<<<< HEAD If you are interested in translating `bn.react.dev`, please see the current translation efforts [here](https://github.com/reactjs/bn.react.dev/issues/1). +======= +If you are interested in translating `react.dev`, please see the current translation efforts [here](https://react.dev/community/translations). +>>>>>>> 15653c0f9b95d6c4845e614e5bcc94c7ee2128f6 ## License Content submitted to [bn.react.dev](https://bn.react.dev/) is CC-BY-4.0 licensed, as found in the [LICENSE-DOCS.md](https://github.com/reactjs/bn.react.dev/blob/main/LICENSE-DOCS.md) file. diff --git a/package.json b/package.json index 31cd864ef..43603db67 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "webpack-bundle-analyzer": "^4.5.0" }, "engines": { - "node": ">=16.8.0" + "node": ">=24" }, "nextBundleAnalysis": { "budget": null, diff --git a/public/images/brand/react-foundation-dark.svg b/public/images/brand/react-foundation-dark.svg new file mode 100644 index 000000000..bc5658e03 --- /dev/null +++ b/public/images/brand/react-foundation-dark.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/brand/react-foundation-light.svg b/public/images/brand/react-foundation-light.svg new file mode 100644 index 000000000..74f7aca68 --- /dev/null +++ b/public/images/brand/react-foundation-light.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/components/Layout/Footer.tsx b/src/components/Layout/Footer.tsx index 50aed2118..5011d00c4 100644 --- a/src/components/Layout/Footer.tsx +++ b/src/components/Layout/Footer.tsx @@ -11,6 +11,7 @@ import * as React from 'react'; import NextLink from 'next/link'; +import Image from 'next/image'; import cn from 'classnames'; import {ExternalLink} from 'components/ExternalLink'; import {IconFacebookCircle} from 'components/Icon/IconFacebookCircle'; @@ -25,273 +26,30 @@ export function Footer() {
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ href="https://react.foundation/" + aria-label="React Foundation" + className="block w-fit"> + +
- Copyright © Meta Platforms, Inc + Copyright © React a Series of LF Projects, LLC and its + contributors.
More Blog React Native - + Privacy - + Terms + + Policies +
- +
@@ -124,7 +124,7 @@ export function TeamMember({ aria-label={`${name} on Threads`} href={`https://threads.net/${threads}`} className="hover:text-primary hover:underline dark:text-primary-dark flex flex-row items-center"> - +
@@ -135,7 +135,7 @@ export function TeamMember({ aria-label={`${name} on Bluesky`} href={`https://bsky.app/profile/${bsky}`} className="hover:text-primary hover:underline dark:text-primary-dark flex flex-row items-center"> - +
@@ -143,19 +143,19 @@ export function TeamMember({ {github && (
- {github} +
)} {personal && ( - {personal} + )}
diff --git a/src/content/blog/2023/03/16/introducing-react-dev.md b/src/content/blog/2023/03/16/introducing-react-dev.md index 96d2a630d..8f47a1645 100644 --- a/src/content/blog/2023/03/16/introducing-react-dev.md +++ b/src/content/blog/2023/03/16/introducing-react-dev.md @@ -42,7 +42,7 @@ When we released React Hooks in 2018, the Hooks docs assumed the reader is famil **The new docs teach React with Hooks from the beginning.** The docs are divided in two main sections: * **[Learn React](/learn)** is a self-paced course that teaches React from scratch. -* **[API Reference](/reference)** provides the details and usage examples for every React API. +* **[API Reference](/reference/react)** provides the details and usage examples for every React API. Let's have a closer look at what you can find in each section. @@ -462,7 +462,7 @@ In the [API Reference](/reference/react), every React API now has a dedicated pa - Built-in Hooks like [`useState`](/reference/react/useState). - Built-in components like [``](/reference/react/Suspense). - Built-in browser components like [``](/reference/react-dom/components/input). -- Framework-oriented APIs like [`renderToPipeableStream`](/reference/react-dom/server/renderToReadableStream). +- Framework-oriented APIs like [`renderToPipeableStream`](/reference/react-dom/server/renderToPipeableStream). - Other React APIs like [`memo`](/reference/react/memo). You'll notice that every API page is split into at least two segments: *Reference* and *Usage*. @@ -607,7 +607,7 @@ button { display: block; margin-top: 10px; } -Some API pages also include [Troubleshooting](/reference/react/useEffect#troubleshooting) (for common problems) and [Alternatives](/reference/react-dom/findDOMNode#alternatives) (for deprecated APIs). +Some API pages also include [Troubleshooting](/reference/react/useEffect#troubleshooting) (for common problems) and [Alternatives](https://18.react.dev/reference/react-dom/findDOMNode#alternatives) (for deprecated APIs). We hope that this approach will make the API reference useful not only as a way to look up an argument, but as a way to see all the different things you can do with any given API—and how it connects to the other ones. diff --git a/src/content/blog/2024/04/25/react-19-upgrade-guide.md b/src/content/blog/2024/04/25/react-19-upgrade-guide.md index 6f918a2a9..99d8a1874 100644 --- a/src/content/blog/2024/04/25/react-19-upgrade-guide.md +++ b/src/content/blog/2024/04/25/react-19-upgrade-guide.md @@ -639,7 +639,7 @@ const ref = useRef(null); ref.current = 1; ``` -`MutableRef` is now deprecated in favor of a single `RefObject` type which `useRef` will always return: +`MutableRefObject` is now deprecated in favor of a single `RefObject` type which `useRef` will always return: ```ts interface RefObject { diff --git a/src/content/blog/2024/12/05/react-19.md b/src/content/blog/2024/12/05/react-19.md index 93ac0c360..1b382b1c7 100644 --- a/src/content/blog/2024/12/05/react-19.md +++ b/src/content/blog/2024/12/05/react-19.md @@ -389,7 +389,7 @@ For more info, see the docs for [Directives](/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](/reference/rsc/server-actions). +For more, see the docs for [React Server Actions](/reference/rsc/server-functions). ## Improvements in React 19 {/*improvements-in-react-19*/} diff --git a/src/content/blog/2025/04/23/react-labs-view-transitions-activity-and-more.md b/src/content/blog/2025/04/23/react-labs-view-transitions-activity-and-more.md index 95821fc43..8bc53d6c8 100644 --- a/src/content/blog/2025/04/23/react-labs-view-transitions-activity-and-more.md +++ b/src/content/blog/2025/04/23/react-labs-view-transitions-activity-and-more.md @@ -14266,7 +14266,7 @@ Unfortunately, some hooks are still hard to think in terms of function instead o We found that often, the confusion is from using an Effect when you don't need to. The [You Might Not Need an Effect](/learn/you-might-not-need-an-effect) guide covers many cases for when Effects are not the right solution. However, even when an Effect is the right fit for a problem, Effects can still be harder to understand than class component lifecycles. -We believe one of the reasons for confusion is that developers to think of Effects from the _component's_ perspective (like a lifecycle), instead of the _Effects_ point of view (what the Effect does). +We believe one of the reasons for confusion is that developers tend to think of Effects from the _component's_ perspective (like a lifecycle), instead of the _Effects_ point of view (what the Effect does). Let's look at an example [from the docs](/learn/lifecycle-of-reactive-effects#thinking-from-the-effects-perspective): diff --git a/src/content/blog/2025/12/11/denial-of-service-and-source-code-exposure-in-react-server-components.md b/src/content/blog/2025/12/11/denial-of-service-and-source-code-exposure-in-react-server-components.md index 206d49e39..1dd4e2b65 100644 --- a/src/content/blog/2025/12/11/denial-of-service-and-source-code-exposure-in-react-server-components.md +++ b/src/content/blog/2025/12/11/denial-of-service-and-source-code-exposure-in-react-server-components.md @@ -76,7 +76,7 @@ Additional disclosures can be frustrating, but they are generally a sign of a he ### Affected frameworks and bundlers {/*affected-frameworks-and-bundlers*/} -Some React frameworks and bundlers depended on, had peer dependencies for, or included the vulnerable React packages. The following React frameworks & bundlers are affected: [next](https://www.npmjs.com/package/next), [react-router](https://www.npmjs.com/package/react-router), [waku](https://www.npmjs.com/package/waku), [@parcel/rsc](https://www.npmjs.com/package/@parcel/rsc), [@vite/rsc-plugin](https://www.npmjs.com/package/@vitejs/plugin-rsc), and [rwsdk](https://www.npmjs.com/package/rwsdk). +Some React frameworks and bundlers depended on, had peer dependencies for, or included the vulnerable React packages. The following React frameworks & bundlers are affected: [next](https://www.npmjs.com/package/next), [react-router](https://www.npmjs.com/package/react-router), [waku](https://www.npmjs.com/package/waku), [@parcel/rsc](https://www.npmjs.com/package/@parcel/rsc), [@vitejs/plugin-rsc](https://www.npmjs.com/package/@vitejs/plugin-rsc), and [rwsdk](https://www.npmjs.com/package/rwsdk). Please see [the instructions in the previous post](/blog/2025/12/03/critical-security-vulnerability-in-react-server-components#update-instructions) for upgrade steps. diff --git a/src/content/community/conferences.md b/src/content/community/conferences.md index 37d3726e7..3286222c3 100644 --- a/src/content/community/conferences.md +++ b/src/content/community/conferences.md @@ -10,26 +10,6 @@ Do you know of a local React.js conference? Add it here! (Please keep the list c ## Upcoming Conferences {/*upcoming-conferences*/} -### ZurichJS Conf 2026 {/*zurichjs-conf-2026*/} -September 10-11, 2026. In-person in Zurich, Switzerland - -[Website](https://conf.zurichjs.com?utm_campaign=ZurichJS_Conf&utm_source=referral&utm_content=reactjs_community_conferences) - [Twitter](https://x.com/zurichjs) - [LinkedIn](https://www.linkedin.com/company/zurichjs/) - -### React Alicante 2026 {/*react-alicante-2026*/} -Sep 24 - 26, 2026. In-person in Alicante - -[Website](https://reactalicante.es//) - [Twitter](https://x.com/ReactAlicante) - -### CityJS Athens 2026 {/*cityjs-athens-2026*/} -October 21-23, 2026. In-person in Athens - -[Website](https://athens.cityjsconf.org/) - [Twitter](https://x.com/cityjsconf) - [Bluesky](https://bsky.app/profile/cityjsconf.bsky.social) - -### React Advanced London 2026 {/*react-advanced-london-2026*/} -October 23 & 26, 2026. In-person in London, UK + online (hybrid event) - -[Website](https://reactadvanced.com/) - [Twitter](https://x.com/reactadvanced) - [LinkedIn](https://www.linkedin.com/showcase/react-advanced-london/) - ### React Summit US 2026 {/*react-summit-us-2026*/} November 17 & 20, 2026. In-person in New York, USA + online (hybrid event) @@ -45,6 +25,11 @@ April 15 & 19, 2027. In-person in Singapore + online (hybrid event) [Website](https://reactsummit.asia/) - [Twitter](https://x.com/reactsummit) - [LinkedIn](https://www.linkedin.com/showcase/reactsummit) +### React Conf Japan 2027 {/*react-conf-japan-2027*/} +April 24, 2027. In-person in Tokyo, Japan + +[Website](https://reactconf.jp/) - [Twitter](https://x.com/reactconfjp) + ### React Summit 2027 {/*react-summit-2027*/} May 21 & 25, 2027. In-person in Amsterdam, Netherlands + online (hybrid event) @@ -53,16 +38,60 @@ May 21 & 25, 2027. In-person in Amsterdam, Netherlands + online (hybrid event) ## Past Conferences {/*past-conferences*/} +### React India 2026 {/*react-india-2026*/} +October 29-31, 2026. In-person in Goa, India -### React Conf Japan 2027 {/*react-conf-japan-2027*/} -April 24, 2027. In-person in Tokyo, Japan +[Website](https://www.reactindia.io/) - [Twitter](https://x.com/react_india) -[Website](https://reactconf.jp/) - [Twitter](https://x.com/reactconfjp) +### React Advanced London 2026 {/*react-advanced-london-2026*/} +October 23 & 26, 2026. In-person in London, UK + online (hybrid event) + +[Website](https://reactadvanced.com/) - [Twitter](https://x.com/reactadvanced) - [LinkedIn](https://www.linkedin.com/showcase/react-advanced-london/) + +### CityJS Athens 2026 {/*cityjs-athens-2026*/} +October 21-23, 2026. In-person in Athens + +[Website](https://athens.cityjsconf.org/) - [Twitter](https://x.com/cityjsconf) - [Bluesky](https://bsky.app/profile/cityjsconf.bsky.social) + +### React Alicante 2026 {/*react-alicante-2026*/} +Sep 24 - 26, 2026. In-person in Alicante + +[Website](https://reactalicante.es//) - [Twitter](https://x.com/ReactAlicante) + +### React Native Connection 2026 {/*react-native-connection-2026*/} +September 24, 2026. In-person in Paris, France + +[Website](https://reactnativeconnection.io/) - [Twitter](https://x.com/ReactNativeConn) - [Bluesky](https://bsky.app/profile/reactnativeconnect.bsky.social) + +### ZurichJS Conf 2026 {/*zurichjs-conf-2026*/} +September 10-11, 2026. In-person in Zurich, Switzerland + +[Website](https://conf.zurichjs.com?utm_campaign=ZurichJS_Conf&utm_source=referral&utm_content=reactjs_community_conferences) - [Twitter](https://x.com/zurichjs) - [LinkedIn](https://www.linkedin.com/company/zurichjs/) + +### Render(ATL) 2026 🍑 {/*renderatl-2026-*/} +August 12-13, 2026. In-person in Atlanta, GA, USA + +[Website](https://renderatl.com/) - [Twitter](https://x.com/renderATL) - [LinkedIn](https://www.linkedin.com/company/renderatl) + +### React Summit 2026 {/*react-summit-2026*/} +June 12 & 16, 2026. In-person in Amsterdam, Netherlands + online (hybrid event) + +[Website](https://reactsummit.com/) - [Twitter](https://x.com/reactsummit) - [LinkedIn](https://www.linkedin.com/showcase/reactsummit) + +### React Norway 2026 {/*react-norway-2026*/} +June 5, 2026. In-person in Oslo, Norway + +[Website](https://reactnorway.com/) - [Twitter](https://x.com/ReactNorway) + +### React Miami 2026 {/*react-miami-2026*/} +April 23-24, 2026. In-person in Miami, FL, USA + +[Website](https://reactmiami.com/) - [Twitter](https://x.com/ReactMiamiConf) ### CityJS London 2026 {/*cityjs-london-2026*/} April 14-17, 2026. In-person in London -[Website](https://india.cityjsconf.org/) - [Twitter](https://x.com/cityjsconf) - [Bluesky](https://bsky.app/profile/cityjsconf.bsky.social) +[Website](https://london.cityjsconf.org/) - [Twitter](https://x.com/cityjsconf) - [Bluesky](https://bsky.app/profile/cityjsconf.bsky.social) ### React Paris 2026 {/*react-paris-2026*/} @@ -79,7 +108,7 @@ February 12-13, 2026. In-person in New Delhi, India ### CityJS Singapore 2026 {/*cityjs-singapore-2026*/} February 4-6, 2026. In-person in Singapore -[Website](https://india.cityjsconf.org/) - [Twitter](https://x.com/cityjsconf) - [Bluesky](https://bsky.app/profile/cityjsconf.bsky.social) +[Website](https://singapore.cityjsconf.org/) - [Twitter](https://x.com/cityjsconf) - [Bluesky](https://bsky.app/profile/cityjsconf.bsky.social) ### React Advanced London 2025 {/*react-advanced-london-2025*/} November 28 & December 1, 2025. In-person in London, UK + online (hybrid event) diff --git a/src/content/learn/describing-the-ui.md b/src/content/learn/describing-the-ui.md index ff39fbd56..2816d0294 100644 --- a/src/content/learn/describing-the-ui.md +++ b/src/content/learn/describing-the-ui.md @@ -530,7 +530,7 @@ React āĻ•āĻŽā§āĻĒā§‹āύ⧇āĻ¨ā§āϟ āĻāĻŦāĻ‚ āĻŽāĻĄāĻŋāωāϞ⧇āϰ āϭ⧇āϤ āĻāĻ•āϟāĻž React āϰ⧇āĻ¨ā§āĻĄāĻžāϰ āĻŸā§āϰāĻŋ āĻšāϞ āĻ•āĻŽā§āĻĒā§‹āύ⧇āĻ¨ā§āĻŸā§‡āϰ āĻŽāĻžāĻā§‡ āĻĨāĻžāĻ•āĻž āĻĒā§āϝāĻžāϰ⧇āĻ¨ā§āϟ-āϚāĻžāχāĻ˛ā§āĻĄ āϏāĻŽā§āĻĒāĻ°ā§āϕ⧇āϰ āĻāĻ•āϟāĻž āĻĒā§āϰāϤāĻŋāĻĢāϞāύāĨ¤ - + React āϰ⧇āĻ¨ā§āĻĄāĻžāϰ āĻŸā§āϰāĻŋā§Ÿā§‡āϰ āĻāĻ•āϟāĻŋ āωāĻĻāĻžāĻšāϰāĻŖāĨ¤ diff --git a/src/content/learn/extracting-state-logic-into-a-reducer.md b/src/content/learn/extracting-state-logic-into-a-reducer.md index 0ea49d695..e26908071 100644 --- a/src/content/learn/extracting-state-logic-into-a-reducer.md +++ b/src/content/learn/extracting-state-logic-into-a-reducer.md @@ -874,7 +874,11 @@ Reducer āĻāϰ āϝ⧇ āĻāĻ•āĻĻāĻŽ āϕ⧋āύ⧋ āĻ–āĻžāϰāĻžāĻĒ āĻĻāĻŋāĻ• āύ⧇ - **āĻŸā§‡āĻ¸ā§āϟ āĻ•āϰāĻž (Testing):** Reducer āĻšāϞ⧋ āĻāĻ•āϟāĻŋ pure function āϝāĻž āφāĻĒāύāĻžāϰ āĻ•āĻŽā§āĻĒā§‹āύ⧇āĻ¨ā§āĻŸā§‡āϰ āωāĻĒāϰ āύāĻŋāĻ°ā§āĻ­āϰ āĻ•āϰ⧇ āύāĻžāĨ¤ āĻāϰ āĻŽāĻžāύ⧇ āφāĻĒāύāĻŋ āĻāϕ⧇ āφāϞāĻžāĻĻāĻž āĻ­āĻžāĻŦ⧇ export āĻ•āϰ⧇ test āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύāĨ¤ āϝāĻĻāĻŋāĻ“ āĻ¸ā§āĻŦāĻžāĻ­āĻžāĻŦāĻŋāĻ•āĻ­āĻžāĻŦ⧇ āĻ•āĻŽā§āĻĒā§‹āύ⧇āĻ¨ā§āϟāϏ āϕ⧇ āφāϰ⧋ realistic environment āĻ āĻŸā§‡āĻ¸ā§āϟ āĻ•āϰāĻž āωāĻ¤ā§āϤāĻŽ, āϤāĻŦ⧇ āϜāϟāĻŋāϞ state update logic āĻāϰ āĻ•ā§āώ⧇āĻ¤ā§āϰ⧇ "āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ initial state āĻāĻŦāĻ‚ action āĻāϰ āϜāĻ¨ā§āϝ āφāĻĒāύāĻžāϰ reducer āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ state āϰāĻŋāϟāĻžāĻ°ā§āύ āĻ•āϰ⧇" āĻ āĻŦā§āϝāĻžāĻĒāĻžāϰ⧇ āύāĻŋāĻļā§āϚāĻŋāϤ āĻĨāĻžāĻ•āĻž āωāĻĒāĻ•āĻžāϰ⧇ āφāϏāϤ⧇ āĻĒāĻžāϰ⧇āĨ¤ - **āĻŦā§āϝāĻžāĻ•ā§āϤāĻŋāĻ—āϤ āĻĒāĻ›āĻ¨ā§āĻĻ (Personal preference):** āϕ⧇āω reducer āĻĒāĻ›āĻ¨ā§āĻĻ āĻ•āϰ⧇, āϕ⧇āω āĻ•āϰ⧇āύāĻžāĨ¤ āĻāϟāĻž āϕ⧋āύ⧋ āϏāĻŽāĻ¸ā§āϝāĻž āύāĻžāĨ¤ āĻāϟāĻž āĻāĻ•āϟāĻž āϰ⧁āϚāĻŋāϰ āĻŦāĻŋāώ⧟āĨ¤ āφāĻĒāύāĻŋ āϏāĻ°ā§āĻŦāĻĻāĻžāχ `useState` āĻāĻŦāĻ‚ `useReducer` āĻāϰ āĻŽāĻžāĻā§‡ āĻ…āĻĻāϞ āĻŦāĻĻāϞ āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύāσ āϤāĻžāϰāĻž āωāϭ⧟āχ āϏāĻŽāĻžāύ! +<<<<<<< HEAD āϝāĻĻāĻŋ āφāĻĒāύāĻŋ āϕ⧋āύ⧋ āĻ•āĻŽā§āĻĒā§‹āύ⧇āĻ¨ā§āĻŸā§‡ āϭ⧁āϞāĻ­āĻžāϞ āĻ¸ā§āĻŸā§‡āϟ āφāĻĒāĻĄā§‡āĻŸā§‡āϰ āĻ•āĻžāϰāϪ⧇ bug āĻāϰ āϏāĻŽā§āĻŽā§āĻ–ā§€āύ āĻšāύ āĻāĻŦāĻ‚ āĻāϰ āϕ⧋āĻĄā§‡āϰ āĻ•āĻžāĻ āĻžāĻŽā§‹ āφāϰ⧋ āϏ⧁āĻ¨ā§āĻĻāϰ āĻ•āϰāϤ⧇ āϚāĻžāύ, āϏ⧇āĻ•ā§āώ⧇āĻ¤ā§āϰ⧇ āφāĻŽāϰāĻž āĻāĻ•āϟāĻŋ reducer āĻŦā§āϝāĻžāĻŦāĻšāĻžāϰ āĻ•āϰāĻž āϰ⧇āĻ•āĻŽā§‡āĻ¨ā§āĻĄ āĻ•āϰāĻŋāĨ¤ āφāĻĒāύāĻžāϰ āϏāĻŦ āĻ•āĻŋāϛ⧁āϰ āϜāĻ¨ā§āϝ reducer āĻŦā§āϝāĻžāĻŦāĻšāĻžāϰ āĻ•āϰāϤ⧇ āĻšāĻŦ⧇ āĻāĻŽāύ āϕ⧋āύ⧋ āĻ•āĻĨāĻž āύ⧇āχāσ āφāĻĒāύāĻŋ āĻŦāĻŋāύāĻž āĻŦāĻžāϧāĻžā§Ÿ āĻŽāĻŋāϞāĻŋā§Ÿā§‡ āĻŽāĻŋāĻļāĻŋā§Ÿā§‡ āĻŦā§āϝāĻžāĻŦāĻšāĻžāϰ āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āύ! āĻāĻŽāύāĻ•āĻŋ āφāĻĒāύāĻŋ āĻāĻ•āχ āĻ•āĻŽā§āĻĒā§‹āύ⧇āĻ¨ā§āĻŸā§‡ `useState` āĻāĻŦāĻ‚ `useReducer` āĻŦā§āϝāĻžāĻŦāĻšāĻžāϰ āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āύāĨ¤ +======= +We recommend using a reducer if you often encounter bugs due to incorrect state updates in some component, and want to introduce more structure to its code. You don't have to use reducers for everything: feel free to mix and match! You can even use `useState` and `useReducer` in the same component. +>>>>>>> 15653c0f9b95d6c4845e614e5bcc94c7ee2128f6 ## āϝ⧇āĻ­āĻžāĻŦ⧇ āĻ­āĻžāϞ⧋ reducer āϞ⧇āĻ–āĻŦ⧇āύ {/*writing-reducers-well*/} diff --git a/src/content/learn/index.md b/src/content/learn/index.md index 90aae8859..f680c4a85 100644 --- a/src/content/learn/index.md +++ b/src/content/learn/index.md @@ -338,7 +338,11 @@ function MyButton() { } ``` +<<<<<<< HEAD React āφāĻĒāύāĻžāϰ āĻ•āĻŽā§āĻĒā§‹āύ⧇āĻ¨ā§āϟ āĻĢāĻžāĻ‚āĻļāύāϕ⧇ āφāĻŦāĻžāϰ āĻ•āϞ āĻ•āϰāĻŦ⧇āĨ¤ āĻāĻŦāĻžāϰ, `count` āĻšāĻŦ⧇ `1`āĨ¤ āĻĒāϰāĻŦāĻ°ā§āϤ⧀āϤ⧇ āĻāϟāĻž āĻšāĻŦ⧇ `2` āĻāĻŦāĻ‚ āĻāĻ­āĻžāĻŦ⧇ āĻŦāĻžā§œāϤ⧇ āĻĨāĻžāĻ•āĻŦ⧇āĨ¤ +======= +Calling `setCount` tells React to call your component function again. This is called a *re-render*. This time, `count` will be `1`. Then it will be `2`. And so on. +>>>>>>> 15653c0f9b95d6c4845e614e5bcc94c7ee2128f6 āφāĻĒāύāĻŋ āϝāĻĻāĻŋ āĻāĻ•āχ component āĻāĻ•āĻžāϧāĻŋāĻ•āĻŦāĻžāϰ render āĻ•āϰ⧇āύ āϤāĻŦ⧇ āĻĒā§āϰāϤāĻŋāϟāĻŋ āϤāĻžāϰ āύāĻŋāϜāĻ¸ā§āĻŦ state āĻĒāĻžāĻŦ⧇āĨ¤ āĻĒā§āϰāϤāĻŋāϟāĻŋ button āĻ āφāϞāĻžāĻĻāĻžāĻ­āĻžāĻŦ⧇ āĻ•ā§āϞāĻŋāĻ• āĻ•āϰ⧁āύ: diff --git a/src/content/learn/lifecycle-of-reactive-effects.md b/src/content/learn/lifecycle-of-reactive-effects.md index 608db09a0..ec3719736 100644 --- a/src/content/learn/lifecycle-of-reactive-effects.md +++ b/src/content/learn/lifecycle-of-reactive-effects.md @@ -1375,7 +1375,7 @@ export default function App() { ``` ```js {expectedErrors: {'react-compiler': [8]}} src/ChatRoom.js active -import { useState, useEffect } from 'react'; +import { useEffect } from 'react'; export default function ChatRoom({ roomId, createConnection }) { useEffect(() => { @@ -1473,7 +1473,7 @@ export default function App() { ``` ```js src/ChatRoom.js active -import { useState, useEffect } from 'react'; +import { useEffect } from 'react'; export default function ChatRoom({ roomId, createConnection }) { useEffect(() => { @@ -1561,7 +1561,7 @@ export default function App() { ``` ```js src/ChatRoom.js active -import { useState, useEffect } from 'react'; +import { useEffect } from 'react'; import { createEncryptedConnection, createUnencryptedConnection, diff --git a/src/content/learn/preserving-and-resetting-state.md b/src/content/learn/preserving-and-resetting-state.md index 685f63ef4..47042cbc4 100644 --- a/src/content/learn/preserving-and-resetting-state.md +++ b/src/content/learn/preserving-and-resetting-state.md @@ -18,7 +18,7 @@ State is isolated between components. React keeps track of which state belongs t ## State is tied to a position in the render tree {/*state-is-tied-to-a-position-in-the-tree*/} -React builds [render trees](learn/understanding-your-ui-as-a-tree#the-render-tree) for the component structure in your UI. +React builds [render trees](/learn/understanding-your-ui-as-a-tree#the-render-tree) for the component structure in your UI. When you give a component state, you might think the state "lives" inside the component. But the state is actually held inside React. React associates each piece of state it's holding with the correct component by where that component sits in the render tree. diff --git a/src/content/learn/react-compiler/introduction.md b/src/content/learn/react-compiler/introduction.md index ff5d6eae4..2b6b26d38 100644 --- a/src/content/learn/react-compiler/introduction.md +++ b/src/content/learn/react-compiler/introduction.md @@ -144,7 +144,7 @@ However, if `expensivelyProcessAReallyLargeArrayOfObjects` is truly an expensive - React Compiler only memoizes React components and hooks, not every function - React Compiler's memoization is not shared across multiple components or hooks -So if `expensivelyProcessAReallyLargeArrayOfObjects` was used in many different components, even if the same exact items were passed down, that expensive calculation would be run repeatedly. We recommend [profiling](reference/react/useMemo#how-to-tell-if-a-calculation-is-expensive) first to see if it really is that expensive before making code more complicated. +So if `expensivelyProcessAReallyLargeArrayOfObjects` was used in many different components, even if the same exact items were passed down, that expensive calculation would be run repeatedly. We recommend [profiling](/reference/react/useMemo#how-to-tell-if-a-calculation-is-expensive) first to see if it really is that expensive before making code more complicated. ## Should I try out the compiler? {/*should-i-try-out-the-compiler*/} diff --git a/src/content/learn/setup.md b/src/content/learn/setup.md index 2c46ee148..b93155cc1 100644 --- a/src/content/learn/setup.md +++ b/src/content/learn/setup.md @@ -17,7 +17,7 @@ TypeScript is a popular way to add type definitions to JavaScript codebases. [Le ## React Developer Tools {/*react-developer-tools*/} -React Developer Tools is a browser extension that can inspect React components, edit props and state, and identify performance problems. Learn how to install it [here](learn/react-developer-tools). +React Developer Tools is a browser extension that can inspect React components, edit props and state, and identify performance problems. Learn how to install it [here](/learn/react-developer-tools). ## React Compiler {/*react-compiler*/} diff --git a/src/content/learn/synchronizing-with-effects.md b/src/content/learn/synchronizing-with-effects.md index 0f7a03344..b0a81cf1b 100644 --- a/src/content/learn/synchronizing-with-effects.md +++ b/src/content/learn/synchronizing-with-effects.md @@ -730,7 +730,12 @@ Effect āĻ `fetch` āĻ•āϞ āϞ⧇āĻ–āĻž [āĻĄā§‡āϟāĻž āĻĢ⧇āϚāĻŋāĻ‚āϝāĻŧ⧇āϰ - **āĻŽā§‚āϞāϤ Effect āĻ āϏāϰāĻžāϏāϰāĻŋ āĻĄā§‡āϟāĻž āĻĢ⧇āϚ āĻ•āϰāĻžāϰ āĻŽāĻžāύ⧇ āĻāχ āϝ⧇, āφāĻĒāύāĻŋ āĻĄā§‡āϟāĻž āĻĒā§āϰāĻŋāϞ⧋āĻĄ āĻŦāĻž āĻ•ā§āϝāĻžāĻļ āĻ•āϰāϤ⧇ āĻĒāĻžāϰāĻŦ⧇āύ āύāĻžāĨ¤** āωāĻĻāĻžāĻšāϰāĻŖāĻ¸ā§āĻŦāϰ⧂āĻĒ, āϝāĻĻāĻŋ āĻ•āĻŽā§āĻĒā§‹āύ⧇āĻ¨ā§āϟāϟāĻŋ āφāύāĻŽāĻžāωāĻ¨ā§āϟ āĻšāϝāĻŧ āĻāĻŦāĻ‚ āĻĒ⧁āύāϰāĻžāϝāĻŧ āĻŽāĻžāωāĻ¨ā§āϟ āĻšāϝāĻŧ, āĻāϟāĻŋāϕ⧇ āĻĒ⧁āύāϰāĻžāϝāĻŧ āĻĄāĻžāϟāĻž āĻĢ⧇āϚ āĻ•āϰāϤ⧇ āĻšāĻŦ⧇āĨ¤ - **āĻāϟāĻž āϖ⧁āĻŦ āĻāĻ•āϟāĻž ergonomic āύāϝāĻŧāĨ¤** āĻĢ⧇āϚ āĻ•āϞ āϞ⧇āĻ–āĻžāϰ āϏāĻŽāϝāĻŧ, āϝāĻžāϤ⧇ [āϰ⧇āϏ āĻ•āĻ¨ā§āĻĄāĻŋāĻļāύ](https://maxrozen.com/race-conditions-fetching-data-react-with-useeffect) āĻāϰ āĻŽāϤ⧋ āĻŦāĻžāϗ⧇ suffer āĻ•āϰāϤ⧇ āύāĻž āĻšā§Ÿ, āϤāĻžāϰ āϜāĻ¨ā§āϝ āĻŦ⧇āĻļ āĻ­āĻžāϞ⧋ āĻĒāϰāĻŋāĻŽāĻžāϪ⧇āϰ āĻŦāϝāĻŧāϞāĻžāϰāĻĒā§āϞ⧇āϟ āϕ⧋āĻĄ āϞ⧇āĻ–āĻž āϞāĻžāϗ⧇āĨ¤ +<<<<<<< HEAD āĻĄāĻžāωāύāϏāĻžāχāĻĄā§‡āϰ āĻāχ āϤāĻžāϞāĻŋāĻ•āĻžāϟāĻŋ React āϜāĻ¨ā§āϝ āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ āύāϝāĻŧāĨ¤ āĻāϟāĻŋ āϝ⧇ āϕ⧋āύ⧋ āϞāĻžāχāĻŦā§āϰ⧇āϰāĻŋāϰ āĻŽāĻžāĻ§ā§āϝāĻŽā§‡ āĻŽāĻžāωāĻ¨ā§āĻŸā§‡āϰ āϏāĻŽā§Ÿ āĻĄā§‡āϟāĻž āĻĢ⧇āĻšā§‡āϰ āĻ•ā§āώ⧇āĻ¤ā§āϰ⧇ āĻĒā§āϰāϝ⧋āĻœā§āϝāĨ¤ āϰāĻžāωāϟāĻŋāĻ‚āϝāĻŧ⧇āϰ āĻŽāϤ⧋, āĻĄā§‡āϟāĻž āĻĢ⧇āϚāĻŋāĻ‚ āĻ­āĻžāϞ⧋āĻ­āĻžāĻŦ⧇ āĻ•āϰāĻž āϏāĻšāϜ āύāϝāĻŧ, āϤāĻžāχ āφāĻŽāϰāĻž āύāĻŋāĻŽā§āύāϞāĻŋāĻ–āĻŋāϤ āĻĒāĻĻā§āϧāϤāĻŋāϰ āĻĒāϰāĻžāĻŽāĻ°ā§āĻļ āĻĻāĻŋāχ: +======= +- **If you use a [framework](/learn/creating-a-react-app#full-stack-frameworks), use its built-in data fetching mechanism.** Modern React frameworks have integrated data fetching mechanisms that are efficient and don't suffer from the above pitfalls. +- **Otherwise, consider using or building a client-side cache.** Popular open source solutions include [TanStack Query](https://tanstack.com/query/latest), [useSWR](https://swr.vercel.app/), and [React Router](https://reactrouter.com/). You can build your own solution too, in which case you would use Effects under the hood, but add logic for deduplicating requests, caching responses, and avoiding network waterfalls (by preloading data or hoisting data requirements to routes). +>>>>>>> 15653c0f9b95d6c4845e614e5bcc94c7ee2128f6 - **āφāĻĒāύāĻŋ āϝāĻĻāĻŋ āĻāĻ•āϟāĻŋ [framework](/learn/creating-a-react-app#full-stack-frameworks) āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰ⧇āύ, āϤāĻžāϰ built-in āĻĄā§‡āϟāĻž āĻĢ⧇āϚāĻŋāĻ‚ āĻĒā§āϰāĻ•ā§āϰāĻŋāϝāĻŧāĻž āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰ⧁āύāĨ¤** āφāϧ⧁āύāĻŋāĻ• āϰāĻŋāϝāĻŧā§āϝāĻžāĻ•ā§āϟ āĻĢā§āϰ⧇āĻŽāĻ“āϝāĻŧāĻžāĻ°ā§āĻ•āϗ⧁āϞāĻŋāϰ āĻŽāĻ§ā§āϝ⧇ integrated āĻĄā§‡āϟāĻž āĻĢ⧇āϚāĻŋāĻ‚ āĻĒā§āϰāĻ•ā§āϰāĻŋāϝāĻŧāĻž āϰāϝāĻŧ⧇āϛ⧇ āϝāĻž āĻ•āĻžāĻ°ā§āϝāĻ•āϰ āĻāĻŦāĻ‚ āωāĻĒāϰ⧇āϰ āϏāĻŽāĻ¸ā§āϝāĻž āϗ⧁āϞ⧋ āĻŽā§āĻ•ā§āϤāĨ¤ - **āĻ…āĻ¨ā§āϝāĻĨāĻžāϝāĻŧ, āĻāĻ•āϟāĻŋ āĻ•ā§āϞāĻžāϝāĻŧ⧇āĻ¨ā§āϟ-āϏāĻžāχāĻĄ āĻ•ā§āϝāĻžāĻļ āχāωāϜ āĻ•āϰ⧁āύ āĻŦāĻž āĻŦāĻŋāĻ˛ā§āĻĄ āĻ•āϰ⧁āύāĨ¤** āϜāύāĻĒā§āϰāĻŋāϝāĻŧ āĻ“āĻĒ⧇āύ āϏ⧋āĻ°ā§āϏ āϏāĻŽāĻžāϧāĻžāύ⧇āϰ āĻŽāĻ§ā§āϝ⧇ [React Query](https://tanstack.com/query/latest), [useSWR](https://swr.vercel.app/), āĻāĻŦāĻ‚ [React Router 6.4+.](https://beta.reactrouter.com/en/main/start/overview) āϰāϝāĻŧ⧇āϛ⧇āĨ¤ āφāĻĒāύāĻŋ āĻāĻ•āϟāĻŋ āύāĻŋāϜāĻ¸ā§āĻŦ āϏāĻŽāĻžāϧāĻžāύ⧋ āϤ⧈āϰāĻŋ āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āύ āĻāχ āĻ•ā§āώ⧇āĻ¤ā§āϰ⧇ āφāĻĒāύāĻŋ Effect āϗ⧁āϞ⧋ āφāĻ¨ā§āĻĄāĻžāϰ āĻĻā§āϝāĻž āĻšā§āĻĄā§‡ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āύ, āϤāĻŦ⧇ request āĻĄāĻŋāĻĄā§āĻĒā§āϞāĻŋāϕ⧇āϟ āĻ•āϰāĻžāϤ⧇, response āĻ•ā§āϝāĻžāĻļ āĻ•āϰāϤ⧇, āĻāĻŦāĻ‚ āύ⧇āϟāĻ“āϝāĻŧāĻžāĻ°ā§āĻ• āĻ“āϝāĻŧāĻžāϟāĻžāϰāĻĢāϞ āĻā§œāĻžāϤ⧇ āϞāϜāĻŋāĻ• add āĻ•āϰ⧁āύāĨ¤ (āĻĄāĻžāϟāĻž āĻĒā§āϰāĻŋāϞ⧋āĻĄāĻŋāĻ‚ āĻ•āϰ⧇ āĻŦāĻž āĻĄāĻžāϟāĻž requirement āϗ⧁āϞ⧋ āϰāĻžāωāĻŸā§‡ hoisting āĻ•āϰ⧇)āĨ¤ diff --git a/src/content/learn/tutorial-tic-tac-toe.md b/src/content/learn/tutorial-tic-tac-toe.md index 56e0cbbf1..de84db45e 100644 --- a/src/content/learn/tutorial-tic-tac-toe.md +++ b/src/content/learn/tutorial-tic-tac-toe.md @@ -1138,7 +1138,7 @@ JavaScript supports [closures](https://developer.mozilla.org/en-US/docs/Web/Java -Now you can add X's to the board... but only to the upper left square. Your `handleClick` function is hardcoded to update the index for the upper left square (`0`). Let's update `handleClick` to be able to update any square. Add an argument `i` to the `handleClick` function that takes the index of the square to update: +Now you can add X's to the board... but only to the upper left square. Your `handleClick` function is hardcoded to update the index for the upper left square (`0`). Let's update `handleClick` to be able to update any square. Add a parameter `i` to the `handleClick` function that takes the index of the square to update: ```js {4,6} export default function Board() { diff --git a/src/content/learn/typescript.md b/src/content/learn/typescript.md index 2e6f7edc5..739efe366 100644 --- a/src/content/learn/typescript.md +++ b/src/content/learn/typescript.md @@ -335,7 +335,7 @@ function MyComponent() { -The [`useMemo`](/reference/react/useMemo) Hooks will create/re-access a memorized value from a function call, re-running the function only when dependencies passed as the 2nd parameter are changed. The result of calling the Hook is inferred from the return value from the function in the first parameter. You can be more explicit by providing a type argument to the Hook. +The [`useMemo`](/reference/react/useMemo) Hooks will create/re-access a memoized value from a function call, re-running the function only when dependencies passed as the 2nd parameter are changed. The result of calling the Hook is inferred from the return value from the function in the first parameter. You can be more explicit by providing a type argument to the Hook. ```ts // The type of visibleTodos is inferred from the return value of filterTodos diff --git a/src/content/learn/understanding-your-ui-as-a-tree.md b/src/content/learn/understanding-your-ui-as-a-tree.md index afc38cd33..497eb48de 100644 --- a/src/content/learn/understanding-your-ui-as-a-tree.md +++ b/src/content/learn/understanding-your-ui-as-a-tree.md @@ -135,7 +135,7 @@ The root node in a React render tree is the [root component](/learn/importing-an #### Where are the HTML tags in the render tree? {/*where-are-the-html-elements-in-the-render-tree*/} -You'll notice in the above render tree, there is no mention of the HTML tags that each component renders. This is because the render tree is only composed of React [components](learn/your-first-component#components-ui-building-blocks). +You'll notice in the above render tree, there is no mention of the HTML tags that each component renders. This is because the render tree is only composed of React [components](/learn/your-first-component#components-ui-building-blocks). React, as a UI framework, is platform agnostic. On react.dev, we showcase examples that render to the web, which uses HTML markup as its UI primitives. But a React app could just as likely render to a mobile or desktop platform, which may use different UI primitives like [UIView](https://developer.apple.com/documentation/uikit/uiview) or [FrameworkElement](https://learn.microsoft.com/en-us/dotnet/api/system.windows.frameworkelement?view=windowsdesktop-7.0). diff --git a/src/content/reference/dev-tools/react-performance-tracks.md b/src/content/reference/dev-tools/react-performance-tracks.md index d4757b9ec..1c10823d3 100644 --- a/src/content/reference/dev-tools/react-performance-tracks.md +++ b/src/content/reference/dev-tools/react-performance-tracks.md @@ -140,7 +140,7 @@ In development builds, when you click on a component render entry, you can inspe The Server Requests track visualized all Promises that eventually end up in a React Server Component. This includes any `async` operations like calling `fetch` or async Node.js file operations. -React will try to combine Promises that are started from inside third-party code into a single span representing the the duration of the entire operation blocking 1st party code. +React will try to combine Promises that are started from inside third-party code into a single span representing the duration of the entire operation blocking 1st party code. For example, a third party library method called `getUser` that calls `fetch` internally multiple times will be represented as a single span called `getUser`, instead of showing multiple `fetch` spans. Clicking on spans will show you a stack trace of where the Promise was created as well as a view of the value that the Promise resolved to, if available. @@ -155,5 +155,5 @@ If you await a Promise, React will display duration of that Promise. To see all Different colors are used to indicate the duration of the component render. The darker the color, the longer the duration. -The Server Components track group will always contain a "Primary" track. If React is able to render Server Components concurrently, it will display addititional "Parallel" tracks. +The Server Components track group will always contain a "Primary" track. If React is able to render Server Components concurrently, it will display additional "Parallel" tracks. If more than 8 Server Components are rendered concurrently, React will associate them with the last "Parallel" track instead of adding more tracks. diff --git a/src/content/reference/eslint-plugin-react-hooks/lints/set-state-in-render.md b/src/content/reference/eslint-plugin-react-hooks/lints/set-state-in-render.md index 7517d5f92..87262949d 100644 --- a/src/content/reference/eslint-plugin-react-hooks/lints/set-state-in-render.md +++ b/src/content/reference/eslint-plugin-react-hooks/lints/set-state-in-render.md @@ -107,4 +107,4 @@ function Counter({max}) { Now the setter only runs in response to the click, React finishes the render normally, and `count` never crosses `max`. -In rare cases, you may need to adjust state based on information from previous renders. For those, follow [this pattern](https://react.dev/reference/react/useState#storing-information-from-previous-renders) of setting state conditionally. +In rare cases, you may need to adjust state based on information from previous renders. For those, follow [this pattern](/reference/react/useState#storing-information-from-previous-renders) of setting state conditionally. diff --git a/src/content/reference/eslint-plugin-react-hooks/lints/use-memo.md b/src/content/reference/eslint-plugin-react-hooks/lints/use-memo.md index a5a77e5f6..56810c359 100644 --- a/src/content/reference/eslint-plugin-react-hooks/lints/use-memo.md +++ b/src/content/reference/eslint-plugin-react-hooks/lints/use-memo.md @@ -79,7 +79,7 @@ function Component({user}) { } ``` -If the side effect sychronizes React state with some external state (or vice versa), use `useEffect`: +If the side effect synchronizes React state with some external state (or vice versa), use `useEffect`: ```js // ✅ Good: Synchronization in useEffect diff --git a/src/content/reference/react-dom/client/createRoot.md b/src/content/reference/react-dom/client/createRoot.md index 282922a62..2f9c35fd6 100644 --- a/src/content/reference/react-dom/client/createRoot.md +++ b/src/content/reference/react-dom/client/createRoot.md @@ -90,7 +90,11 @@ React `root`-āĻ `` āĻĻ⧇āĻ–āĻžāĻŦ⧇, āĻāĻŦāĻ‚ āĻāϰ āĻŽāĻ§ā§āϝāĻ• * āφāĻĒāύāĻŋ āϝāĻĻāĻŋ āĻāĻ•āĻŋ āϰ⧁āĻŸā§‡ āĻāĻ•āĻžāϧāĻŋāĻ•āĻŦāĻžāϰ `render` āĻ•āϞ āĻ•āϰ⧇āύ, āϤāĻžāĻšāϞ⧇ āφāĻĒāύāĻžāϰ āĻĒāĻžāĻ āĻžāύ⧋ āϏāĻ°ā§āĻŦāĻļ⧇āώ JSX āĻĻ⧇āĻ–āĻžāύ⧋āϰ āĻ–āĻžāϤāĻŋāϰ⧇ React āĻĒā§āĻ°ā§Ÿā§‹āϜāύāĻŽāϤ DOM āφāĻĒāĻĄā§‡āϟ āĻ•āϰ⧇ āĻĢ⧇āϞāĻŦ⧇āĨ¤ React āφāϗ⧇āϰāĻŦāĻžāϰ āϰ⧇āĻ¨ā§āĻĄāĻžāϰ āĻšāĻ“ā§ŸāĻž āĻŸā§āϰāĻŋ āĻāϰ āϏāĻžāĻĨ⧇ ["āĻŽāĻŋāϞāĻŋā§Ÿā§‡ āĻĻ⧇āĻ–āĻŦ⧇"](/learn/preserving-and-resetting-state) āĻāĻŦāĻ‚ āϏāĻŋāĻĻā§āϧāĻžāĻ¨ā§āϤ āύāĻŋāĻŦ⧇ DOM āĻāϰ āϕ⧋āĻŖ āĻ…āĻ‚āĻļāϗ⧁āϞ⧋ āĻĒ⧁āύāĻ°ā§āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻž āϝāĻžā§Ÿ āφāϰ āϕ⧋āύāϗ⧁āϞ⧋ āφāĻŦāĻžāϰ āĻŦāĻžāύāĻžāϤ⧇ āĻšāĻŦ⧇āĨ¤ āĻāĻ•āχ āϰ⧁āĻŸā§‡ āφāĻŦāĻžāϰ `render` āĻ•āϞ āĻ•āϰāĻž āϰ⧁āϟ āĻ•āĻŽā§āĻĒā§‹āύ⧇āĻ¨ā§āĻŸā§‡ [`set` function](/reference/react/useState#setstate) āĻ•āϞ āĻ•āϰāĻžāϰ āĻŽāϤāσ React āĻ…āĻĒā§āĻ°ā§Ÿā§‹āϜāĻ¨ā§€ā§Ÿ DOM āφāĻĒāĻĄā§‡āϟ āĻā§œāĻžāύ⧋āϰ āĻšā§‡āĻˇā§āϟāĻž āĻ•āϰ⧇āĨ¤ +<<<<<<< HEAD * āϝāĻĻāĻŋāĻ“ rendering āĻļ⧁āϰ⧁ āĻšāĻ“āϝāĻŧāĻžāϰ āĻĒāϰ synchronous, `root.render(...)` synchronous āύāϝāĻŧāĨ¤ āĻāϰ āĻŽāĻžāύ⧇ āĻšāϞ `root.render()` āĻāϰ āĻĒāϰ⧇āϰ āϕ⧋āĻĄ āĻ“āχ āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ render āĻāϰ āϕ⧋āύ effects (`useLayoutEffect`, `useEffect`) fire āĻšāĻ“āϝāĻŧāĻžāϰ āφāϗ⧇āχ āϰāĻžāύ āĻšāϤ⧇ āĻĒāĻžāϰ⧇āĨ¤ āĻāϟāĻž āϏāĻžāϧāĻžāϰāĻŖāϤ āĻ āĻŋāĻ• āφāϛ⧇ āĻāĻŦāĻ‚ āϖ⧁āĻŦ āĻ•āĻŽāχ adjustment āĻĒā§āϰāϝāĻŧā§‹āϜāύ āĻšāϝāĻŧāĨ¤ āĻŦāĻŋāϰāϞ āĻ•ā§āώ⧇āĻ¤ā§āϰ⧇ āϝ⧇āĻ–āĻžāύ⧇ effect timing āϗ⧁āϰ⧁āĻ¤ā§āĻŦāĻĒā§‚āĻ°ā§āĻŖ, āφāĻĒāύāĻŋ `root.render(...)` āϕ⧇ [`flushSync`](/reference/react-dom/flushSync) āĻĻāĻŋāϝāĻŧ⧇ wrap āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āύ āϝāĻžāϤ⧇ initial render āϏāĻŽā§āĻĒā§‚āĻ°ā§āĻŖāĻ­āĻžāĻŦ⧇ synchronously āϰāĻžāύ āĻšāϝāĻŧāĨ¤ +======= +* Although rendering is synchronous once it starts, `root.render(...)` is not. This means code after `root.render()` may run before any effects (`useLayoutEffect`, `useEffect`) of that specific render are fired. This is usually fine and rarely needs adjustment. In rare cases where effect timing matters, you can wrap `root.render(...)` in [`flushSync`](/reference/react-dom/flushSync) to ensure the initial render runs fully synchronously. +>>>>>>> 15653c0f9b95d6c4845e614e5bcc94c7ee2128f6 ```js const root = createRoot(document.getElementById('root')); @@ -379,7 +383,11 @@ const root = createRoot(container, { 1. āϝ⧇ error throw āĻšāϝāĻŧ⧇āϛ⧇āĨ¤ 2. āĻāĻ•āϟāĻŋ errorInfo āĻ…āĻŦāĻœā§‡āĻ•ā§āϟ āϝāĻžāϤ⧇ error āĻāϰ componentStack āϰāϝāĻŧ⧇āϛ⧇āĨ¤ +<<<<<<< HEAD `onUncaughtError` āĻāĻŦāĻ‚ `onRecoverableError` āĻāϰ āϏāĻžāĻĨ⧇ āĻāĻ•āĻ¤ā§āϰ⧇, āφāĻĒāύāĻŋ āφāĻĒāύāĻžāϰ āύāĻŋāϜāĻ¸ā§āĻŦ error reporting system implement āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āύāσ +======= +Together with `onUncaughtError` and `onRecoverableError`, you can implement your own error reporting system: +>>>>>>> 15653c0f9b95d6c4845e614e5bcc94c7ee2128f6 @@ -417,9 +425,15 @@ import { const container = document.getElementById("root"); const root = createRoot(container, { +<<<<<<< HEAD // āĻŽāύ⧇ āϰāĻžāĻ–āĻŦ⧇āύ development āĻ āĻāχ options āϗ⧁āϞ⧋ āϏāϰāĻŋāϝāĻŧ⧇ āĻĻāĻŋāύ āϝāĻžāϤ⧇ // React āĻāϰ default handlers āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āύ āĻŦāĻž development āĻāϰ āϜāĻ¨ā§āϝ āφāĻĒāύāĻžāϰ āύāĻŋāϜāĻ¸ā§āĻŦ overlay implement āĻ•āϰāϤ⧇ āĻĒāĻžāϰ⧇āύāĨ¤ // handlers āϗ⧁āϞ⧋ āĻāĻ–āĻžāύ⧇ āĻļ⧁āϧ⧁āĻŽāĻžāĻ¤ā§āϰ demonstration āωāĻĻā§āĻĻ⧇āĻļā§āϝ⧇ unconditionally specify āĻ•āϰāĻž āĻšāϝāĻŧ⧇āϛ⧇āĨ¤ +======= + // Keep in mind to remove these options in development to leverage + // React's default handlers or implement your own overlay for development. + // The handlers are only specified unconditionally here for demonstration purposes. +>>>>>>> 15653c0f9b95d6c4845e614e5bcc94c7ee2128f6 onCaughtError: onCaughtErrorProd, onRecoverableError: onRecoverableErrorProd, onUncaughtError: onUncaughtErrorProd, diff --git a/src/content/reference/react-dom/client/hydrateRoot.md b/src/content/reference/react-dom/client/hydrateRoot.md index 3bb2ae865..974e07b3d 100644 --- a/src/content/reference/react-dom/client/hydrateRoot.md +++ b/src/content/reference/react-dom/client/hydrateRoot.md @@ -124,7 +124,11 @@ root.unmount(); ### āϏāĻžāĻ°ā§āĻ­āĻžāϰ-āϰ⧇āĻ¨ā§āĻĄāĻžāĻ°ā§āĻĄ HTML āĻāϰ hydrating {/*hydrating-server-rendered-html*/} +<<<<<<< HEAD āφāĻĒāύāĻžāϰ āĻ…ā§āϝāĻžāĻĒ⧇āϰ HTML āϝāĻĻāĻŋ [`react-dom/server`](/reference/react-dom/client/createRoot) āĻĻāĻŋā§Ÿā§‡ āĻŦāĻžāύāĻžāύ⧋ āĻšā§Ÿā§‡ āĻĨāĻžāϕ⧇, āφāĻĒāύāĻžāϕ⧇ āĻāϕ⧇ āĻ•ā§āϞāĻžā§Ÿā§‡āĻ¨ā§āĻŸā§‡ *hydrate* āĻ•āϰāϤ⧇ āĻšāĻŦ⧇āĨ¤ +======= +If your app's HTML was generated by [`react-dom/server`](/reference/react-dom/server), you need to *hydrate* it on the client. +>>>>>>> 15653c0f9b95d6c4845e614e5bcc94c7ee2128f6 ```js [[1, 3, "document.getElementById('root')"], [2, 3, ""]] import { hydrateRoot } from 'react-dom/client'; @@ -447,9 +451,15 @@ import { const container = document.getElementById("root"); hydrateRoot(container, , { +<<<<<<< HEAD // āĻŽāύ⧇ āϰāĻžāĻ–āĻŦ⧇āύ development āĻ React āĻāϰ default handler āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāϤ⧇ āĻŦāĻž // development āĻāϰ āϜāĻ¨ā§āϝ āύāĻŋāϜāĻ¸ā§āĻŦ overlay āĻŦāĻžāĻ¸ā§āϤāĻŦāĻžāϝāĻŧāύ āĻ•āϰāϤ⧇ āĻāχ option āϗ⧁āϞ⧋ āϏāϰāĻžāύāĨ¤ // handler āϗ⧁āϞ⧋ āĻļ⧁āϧ⧁āĻŽāĻžāĻ¤ā§āϰ āĻĒā§āϰāĻĻāĻ°ā§āĻļāύ⧇āϰ āωāĻĻā§āĻĻ⧇āĻļā§āϝ⧇ āύāĻŋāσāĻļāĻ°ā§āϤāĻ­āĻžāĻŦ⧇ āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ āĻ•āϰāĻž āĻšāϝāĻŧ⧇āϛ⧇āĨ¤ +======= + // Keep in mind to remove these options in development to leverage + // React's default handlers or implement your own overlay for development. + // The handlers are only specified unconditionally here for demonstration purposes. +>>>>>>> 15653c0f9b95d6c4845e614e5bcc94c7ee2128f6 onCaughtError: onCaughtErrorProd, onRecoverableError: onRecoverableErrorProd, onUncaughtError: onUncaughtErrorProd, diff --git a/src/content/reference/react-dom/components/common.md b/src/content/reference/react-dom/components/common.md index f81788da0..a70035947 100644 --- a/src/content/reference/react-dom/components/common.md +++ b/src/content/reference/react-dom/components/common.md @@ -257,9 +257,9 @@ Instead of a ref object (like the one returned by [`useRef`](/reference/react/us [See an example of using the `ref` callback.](/learn/manipulating-the-dom-with-refs#how-to-manage-a-list-of-refs-using-a-ref-callback) -When the `
` DOM node is added to the screen, React will call your `ref` callback with the DOM `node` as the argument. When that `
` DOM node is removed, React will call your the cleanup function returned from the callback. +When the `
` DOM node is added to the screen, React will call your `ref` callback with the DOM `node` as the argument. When that `
` DOM node is removed, React will call the cleanup function returned from the callback. -React will also call your `ref` callback whenever you pass a *different* `ref` callback. In the above example, `(node) => { ... }` is a different function on every render. When your component re-renders, the *previous* function will be called with `null` as the argument, and the *next* function will be called with the DOM node. +React will also call your `ref` callback whenever you pass a *different* `ref` callback. In the above example, `(node) => { ... }` is a different function on every render. When your component re-renders, the cleanup function returned by the *previous* function will be called, and the *next* function will be called with the DOM node. If no cleanup function is returned, the *previous* function will be called with `null` as the argument instead. #### Parameters {/*ref-callback-parameters*/} diff --git a/src/content/reference/react-dom/components/form.md b/src/content/reference/react-dom/components/form.md index 10e9c6794..100d60f6d 100644 --- a/src/content/reference/react-dom/components/form.md +++ b/src/content/reference/react-dom/components/form.md @@ -38,21 +38,27 @@ To create interactive controls for submitting information, render the [built-in `
` supports all [common element props.](/reference/react-dom/components/common#common-props) -[`action`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#action): a URL or function. When a URL is passed to `action` the form will behave like the HTML form component. When a function is passed to `action` the function will handle the form submission in a Transition following [the Action prop pattern](/reference/react/useTransition#exposing-action-props-from-components). The function passed to `action` may be async and will be called with a single argument containing the [form data](https://developer.mozilla.org/en-US/docs/Web/API/FormData) of the submitted form. The `action` prop can be overridden by a `formAction` attribute on a `