mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-21 19:31:57 +00:00
Original commit changeset: d52b3ec734
Revert this so we can just fix the real deadlinks.
This commit is contained in:
@@ -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/react)** provides the details and usage examples for every React API.
|
||||
* **[API Reference](/reference)** provides the details and usage examples for every React API.
|
||||
|
||||
Let's have a closer look at what you can find in each section.
|
||||
|
||||
@@ -607,7 +607,7 @@ button { display: block; margin-top: 10px; }
|
||||
|
||||
</Recipes>
|
||||
|
||||
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).
|
||||
Some API pages also include [Troubleshooting](/reference/react/useEffect#troubleshooting) (for common problems) and [Alternatives](/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.
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ The biggest change is that we introduced [`async` / `await`](https://github.com/
|
||||
|
||||
Now that we have data fetching pretty well sorted, we're exploring the other direction: sending data from the client to the server, so that you can execute database mutations and implement forms. We're doing this by letting you pass Server Action functions across the server/client boundary, which the client can then call, providing seamless RPC. Server Actions also give you progressively enhanced forms before JavaScript loads.
|
||||
|
||||
React Server Components has shipped in [Next.js App Router](/learn/creating-a-react-app#nextjs-app-router). This showcases a deep integration of a router that really buys into RSC as a primitive, but it's not the only way to build a RSC-compatible router and framework. There's a clear separation for features provided by the RSC spec and implementation. React Server Components is meant as a spec for components that work across compatible React frameworks.
|
||||
React Server Components has shipped in [Next.js App Router](/learn/start-a-new-react-project#nextjs-app-router). This showcases a deep integration of a router that really buys into RSC as a primitive, but it's not the only way to build a RSC-compatible router and framework. There's a clear separation for features provided by the RSC spec and implementation. React Server Components is meant as a spec for components that work across compatible React frameworks.
|
||||
|
||||
We generally recommend using an existing framework, but if you need to build your own custom framework, it is possible. Building your own RSC-compatible framework is not as easy as we'd like it to be, mainly due to the deep bundler integration needed. The current generation of bundlers are great for use on the client, but they weren't designed with first-class support for splitting a single module graph between the server and the client. This is why we're now partnering directly with bundler developers to get the primitives for RSC built-in.
|
||||
|
||||
@@ -92,7 +92,7 @@ Since our last update, we've tested an experimental version of prerendering inte
|
||||
|
||||
## Transition Tracing {/*transition-tracing*/}
|
||||
|
||||
The Transition Tracing API lets you detect when [React Transitions](/reference/react/useTransition) become slower and investigate why they may be slow. Following our last update, we have completed the initial design of the API and published an [RFC](https://github.com/reactjs/rfcs/pull/238). The basic capabilities have also been implemented. The project is currently on hold. We welcome feedback on the RFC and look forward to resuming its development to provide a better performance measurement tool for React. This will be particularly useful with routers built on top of React Transitions, like the [Next.js App Router](/learn/creating-a-react-app#nextjs-app-router).
|
||||
The Transition Tracing API lets you detect when [React Transitions](/reference/react/useTransition) become slower and investigate why they may be slow. Following our last update, we have completed the initial design of the API and published an [RFC](https://github.com/reactjs/rfcs/pull/238). The basic capabilities have also been implemented. The project is currently on hold. We welcome feedback on the RFC and look forward to resuming its development to provide a better performance measurement tool for React. This will be particularly useful with routers built on top of React Transitions, like the [Next.js App Router](/learn/start-a-new-react-project#nextjs-app-router).
|
||||
|
||||
* * *
|
||||
In addition to this update, our team has made recent guest appearances on community podcasts and livestreams to speak more on our work and answer questions.
|
||||
|
||||
@@ -107,7 +107,7 @@ Activity is still under research and our remaining work is to finalize the primi
|
||||
|
||||
In addition to this update, our team has presented at conferences and made appearances on podcasts to speak more on our work and answer questions.
|
||||
|
||||
- [Sathya Gunasekaran](https://github.com/gsathya) spoke about the React Compiler at the [React India](https://www.youtube.com/watch?v=kjOacmVsLSE) conference
|
||||
- [Sathya Gunasekaran](/community/team#sathya-gunasekaran) spoke about the React Compiler at the [React India](https://www.youtube.com/watch?v=kjOacmVsLSE) conference
|
||||
|
||||
- [Dan Abramov](/community/team#dan-abramov) gave a talk at [RemixConf](https://www.youtube.com/watch?v=zMf_xeGPn6s) titled “React from Another Dimension” which explores an alternative history of how React Server Components and Actions could have been created
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ For a list of all available codemods, see the [`react-codemod` repo](https://git
|
||||
|
||||
In previous versions of React, errors thrown during render were caught and rethrown. In DEV, we would also log to `console.error`, resulting in duplicate error logs.
|
||||
|
||||
In React 19, we've [improved how errors are handled](/blog/2024/12/05/react-19#error-handling) to reduce duplication by not re-throwing:
|
||||
In React 19, we've [improved how errors are handled](/blog/2024/04/25/react-19#error-handling) to reduce duplication by not re-throwing:
|
||||
|
||||
- **Uncaught Errors**: Errors that are not caught by an Error Boundary are reported to `window.reportError`.
|
||||
- **Caught Errors**: Errors that are caught by an Error Boundary are reported to `console.error`.
|
||||
@@ -499,7 +499,7 @@ function AutoselectingInput() {
|
||||
|
||||
### Deprecated: `element.ref` {/*deprecated-element-ref*/}
|
||||
|
||||
React 19 supports [`ref` as a prop](/blog/2024/12/05/react-19#ref-as-a-prop), so we're deprecating the `element.ref` in place of `element.props.ref`.
|
||||
React 19 supports [`ref` as a prop](/blog/2024/04/25/react-19#ref-as-a-prop), so we're deprecating the `element.ref` in place of `element.props.ref`.
|
||||
|
||||
Accessing `element.ref` will warn:
|
||||
|
||||
|
||||
@@ -355,7 +355,7 @@ For more information, see [React DOM Static APIs](/reference/react-dom/static).
|
||||
|
||||
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#react-server-conditional-exports) for use in frameworks that support the [Full-stack React Architecture](/learn/creating-a-react-app#which-features-make-up-the-react-teams-full-stack-architecture-vision).
|
||||
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#react-server-conditional-exports) for use in frameworks that support the [Full-stack React Architecture](/learn/start-a-new-react-project#which-features-make-up-the-react-teams-full-stack-architecture-vision).
|
||||
|
||||
|
||||
<Note>
|
||||
@@ -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-functions).
|
||||
For more, see the docs for [React Server Actions](/reference/rsc/server-actions).
|
||||
|
||||
## Improvements in React 19 {/*improvements-in-react-19*/}
|
||||
|
||||
|
||||
@@ -2495,7 +2495,7 @@ For example, we can slow down the `default` cross fade animation:
|
||||
</ViewTransition>
|
||||
```
|
||||
|
||||
And define `slow-fade` in CSS using [view transition classes](/reference/react/ViewTransition#view-transition-class):
|
||||
And define `slow-fade` in CSS using [view transition classes](/reference/react/ViewTransition#view-transition-classes):
|
||||
|
||||
```css
|
||||
::view-transition-old(.slow-fade) {
|
||||
|
||||
@@ -20,11 +20,11 @@ Let's say you have an existing web app at `example.com` built with another serve
|
||||
|
||||
Here's how we recommend to set it up:
|
||||
|
||||
1. **Build the React part of your app** using one of the [React-based frameworks](/learn/creating-a-react-app).
|
||||
1. **Build the React part of your app** using one of the [React-based frameworks](/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/app/api-reference/config/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](/learn/creating-a-react-app#full-stack-frameworks) baked into those frameworks.
|
||||
This ensures the React part of your app can [benefit from the best practices](/learn/start-a-new-react-project#can-i-use-react-without-a-framework) 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.
|
||||
|
||||
@@ -149,7 +149,7 @@ 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](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) 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](/learn/creating-a-react-app) right after to get the most out of React.
|
||||
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](/learn/start-a-new-react-project) right after to get the most out of React.
|
||||
|
||||
## Using React Native in an existing native mobile app {/*using-react-native-in-an-existing-native-mobile-app*/}
|
||||
|
||||
|
||||
@@ -732,7 +732,7 @@ Writing `fetch` calls inside Effects is a [popular way to fetch data](https://ww
|
||||
|
||||
This list of downsides is not specific to React. It applies to fetching data on mount with any library. Like with routing, data fetching is not trivial to do well, so we recommend the following approaches:
|
||||
|
||||
- **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.
|
||||
- **If you use a [framework](/learn/start-a-new-react-project#production-grade-react-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 [React Query](https://tanstack.com/query/latest), [useSWR](https://swr.vercel.app/), and [React Router 6.4+.](https://beta.reactrouter.com/en/main/start/overview) 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).
|
||||
|
||||
You can continue fetching data directly in Effects if neither of these approaches suit you.
|
||||
|
||||
@@ -13,14 +13,14 @@ TypeScript is a popular way to add type definitions to JavaScript codebases. Out
|
||||
|
||||
* [TypeScript with React Components](/learn/typescript#typescript-with-react-components)
|
||||
* [Examples of typing with Hooks](/learn/typescript#example-hooks)
|
||||
* [Common types from `@types/react`](/learn/typescript#useful-types)
|
||||
* [Further learning locations](/learn/typescript#further-learning)
|
||||
* [Common types from `@types/react`](/learn/typescript/#useful-types)
|
||||
* [Further learning locations](/learn/typescript/#further-learning)
|
||||
|
||||
</YouWillLearn>
|
||||
|
||||
## Installation {/*installation*/}
|
||||
|
||||
All [production-grade React frameworks](/learn/creating-a-react-app#full-stack-frameworks) offer support for using TypeScript. Follow the framework specific guide for installation:
|
||||
All [production-grade React frameworks](/learn/start-a-new-react-project#production-grade-react-frameworks) offer support for using TypeScript. Follow the framework specific guide for installation:
|
||||
|
||||
- [Next.js](https://nextjs.org/docs/app/building-your-application/configuring/typescript)
|
||||
- [Remix](https://remix.run/docs/en/1.19.2/guides/typescript)
|
||||
|
||||
@@ -26,7 +26,7 @@ There are two common cases in which you don't need Effects:
|
||||
* **You don't need Effects to transform data for rendering.** For example, let's say you want to filter a list before displaying it. You might feel tempted to write an Effect that updates a state variable when the list changes. However, this is inefficient. When you update the state, React will first call your component functions to calculate what should be on the screen. Then React will ["commit"](/learn/render-and-commit) these changes to the DOM, updating the screen. Then React will run your Effects. If your Effect *also* immediately updates the state, this restarts the whole process from scratch! To avoid the unnecessary render passes, transform all the data at the top level of your components. That code will automatically re-run whenever your props or state change.
|
||||
* **You don't need Effects to handle user events.** For example, let's say you want to send an `/api/buy` POST request and show a notification when the user buys a product. In the Buy button click event handler, you know exactly what happened. By the time an Effect runs, you don't know *what* the user did (for example, which button was clicked). This is why you'll usually handle user events in the corresponding event handlers.
|
||||
|
||||
You *do* need Effects to [synchronize](/learn/synchronizing-with-effects#what-are-effects-and-how-are-they-different-from-events) with external systems. For example, you can write an Effect that keeps a jQuery widget synchronized with the React state. You can also fetch data with Effects: for example, you can synchronize the search results with the current search query. Keep in mind that modern [frameworks](/learn/creating-a-react-app#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than writing Effects directly in your components.
|
||||
You *do* need Effects to [synchronize](/learn/synchronizing-with-effects#what-are-effects-and-how-are-they-different-from-events) with external systems. For example, you can write an Effect that keeps a jQuery widget synchronized with the React state. You can also fetch data with Effects: for example, you can synchronize the search results with the current search query. Keep in mind that modern [frameworks](/learn/start-a-new-react-project#production-grade-react-frameworks) provide more efficient built-in data fetching mechanisms than writing Effects directly in your components.
|
||||
|
||||
To help you gain the right intuition, let's look at some common concrete examples!
|
||||
|
||||
@@ -751,7 +751,7 @@ This ensures that when your Effect fetches data, all responses except the last r
|
||||
|
||||
Handling race conditions is not the only difficulty with implementing data fetching. You might also want to think about caching responses (so that the user can click Back and see the previous screen instantly), how to fetch data on the server (so that the initial server-rendered HTML contains the fetched content instead of a spinner), and how to avoid network waterfalls (so that a child can fetch data without waiting for every parent).
|
||||
|
||||
**These issues apply to any UI library, not just React. Solving them is not trivial, which is why modern [frameworks](/learn/creating-a-react-app#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than fetching data in Effects.**
|
||||
**These issues apply to any UI library, not just React. Solving them is not trivial, which is why modern [frameworks](/learn/start-a-new-react-project#production-grade-react-frameworks) provide more efficient built-in data fetching mechanisms than fetching data in Effects.**
|
||||
|
||||
If you don't use a framework (and don't want to build your own) but would like to make data fetching from Effects more ergonomic, consider extracting your fetching logic into a custom Hook like in this example:
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ Your React application begins at a "root" component. Usually, it is created auto
|
||||
|
||||
Most React apps use components all the way down. This means that you won't only use components for reusable pieces like buttons, but also for larger pieces like sidebars, lists, and ultimately, complete pages! Components are a handy way to organize UI code and markup, even if some of them are only used once.
|
||||
|
||||
[React-based frameworks](/learn/creating-a-react-app) take this a step further. Instead of using an empty HTML file and letting React "take over" managing the page with JavaScript, they *also* generate the HTML automatically from your React components. This allows your app to show some content before the JavaScript code loads.
|
||||
[React-based frameworks](/learn/start-a-new-react-project) take this a step further. Instead of using an empty HTML file and letting React "take over" managing the page with JavaScript, they *also* generate the HTML automatically from your React components. This allows your app to show some content before the JavaScript code loads.
|
||||
|
||||
Still, many websites only use React to [add interactivity to existing HTML pages.](/learn/add-react-to-an-existing-project#using-react-for-a-part-of-your-existing-page) They have many root components instead of a single one for the entire page. You can use as much—or as little—React as you need.
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ When your HTML is empty, the user sees a blank page until the app's JavaScript c
|
||||
<div id="root"></div>
|
||||
```
|
||||
|
||||
This can feel very slow! To solve this, you can generate the initial HTML from your components [on the server or during the build.](/reference/react-dom/server) Then your visitors can read text, see images, and click links before any of the JavaScript code loads. We recommend [using a framework](/learn/creating-a-react-app#full-stack-frameworks) that does this optimization out of the box. Depending on when it runs, this is called *server-side rendering (SSR)* or *static site generation (SSG).*
|
||||
This can feel very slow! To solve this, you can generate the initial HTML from your components [on the server or during the build.](/reference/react-dom/server) Then your visitors can read text, see images, and click links before any of the JavaScript code loads. We recommend [using a framework](/learn/start-a-new-react-project#production-grade-react-frameworks) that does this optimization out of the box. Depending on when it runs, this is called *server-side rendering (SSR)* or *static site generation (SSG).*
|
||||
|
||||
</Note>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ title: Client React DOM APIs
|
||||
|
||||
<Intro>
|
||||
|
||||
The `react-dom/client` APIs let you render React components on the client (in the browser). These APIs are typically used at the top level of your app to initialize your React tree. A [framework](/learn/creating-a-react-app#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
|
||||
The `react-dom/client` APIs let you render React components on the client (in the browser). These APIs are typically used at the top level of your app to initialize your React tree. A [framework](/learn/start-a-new-react-project#production-grade-react-frameworks) may call them for you. Most of your components don't need to import or use them.
|
||||
|
||||
</Intro>
|
||||
|
||||
|
||||
@@ -916,7 +916,7 @@ export default function Form() {
|
||||
|
||||
</Sandpack>
|
||||
|
||||
Read more about [manipulating DOM with refs](/learn/manipulating-the-dom-with-refs) and [check out more examples.](/reference/react/useRef#usage)
|
||||
Read more about [manipulating DOM with refs](/learn/manipulating-the-dom-with-refs) and [check out more examples.](/reference/react/useRef#examples-dom)
|
||||
|
||||
For more advanced use cases, the `ref` attribute also accepts a [callback function.](#ref-callback)
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ To create interactive controls for submitting information, render the [built-in
|
||||
|
||||
#### Props {/*props*/}
|
||||
|
||||
`<form>` supports all [common element props.](/reference/react-dom/components/common#common-props)
|
||||
`<form>` supports all [common element props.](/reference/react-dom/components/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. 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 `<button>`, `<input type="submit">`, or `<input type="image">` component.
|
||||
|
||||
@@ -230,7 +230,7 @@ export async function deliverMessage(message) {
|
||||
</Sandpack>
|
||||
|
||||
[//]: # 'Uncomment the next line, and delete this line after the `useOptimistic` reference documentatino page is published'
|
||||
[//]: # 'To learn more about the `useOptimistic` Hook see the [reference documentation](/reference/react/useOptimistic).'
|
||||
[//]: # 'To learn more about the `useOptimistic` Hook see the [reference documentation](/reference/react/hooks/useOptimistic).'
|
||||
|
||||
### Handling form submission errors {/*handling-form-submission-errors*/}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ To display an input, render the [built-in browser `<input>`](https://developer.m
|
||||
|
||||
#### Props {/*props*/}
|
||||
|
||||
`<input>` supports all [common element props.](/reference/react-dom/components/common#common-props)
|
||||
`<input>` supports all [common element props.](/reference/react-dom/components/common#props)
|
||||
|
||||
- [`formAction`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formaction): A string or function. Overrides the parent `<form action>` for `type="submit"` and `type="image"`. When a URL is passed to `action` the form will behave like a standard HTML form. When a function is passed to `formAction` the function will handle the form submission. See [`<form action>`](/reference/react-dom/components/form#props).
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ To link to external resources such as stylesheets, fonts, and icons, or to annot
|
||||
|
||||
#### Props {/*props*/}
|
||||
|
||||
`<link>` supports all [common element props.](/reference/react-dom/components/common#common-props)
|
||||
`<link>` supports all [common element props.](/reference/react-dom/components/common#props)
|
||||
|
||||
* `rel`: a string, required. Specifies the [relationship to the resource](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel). React [treats links with `rel="stylesheet"` differently](#special-rendering-behavior) from other links.
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ To add document metadata, render the [built-in browser `<meta>` component](https
|
||||
|
||||
#### Props {/*props*/}
|
||||
|
||||
`<meta>` supports all [common element props.](/reference/react-dom/components/common#common-props)
|
||||
`<meta>` supports all [common element props.](/reference/react-dom/components/common#props)
|
||||
|
||||
It should have *exactly one* of the following props: `name`, `httpEquiv`, `charset`, `itemProp`. The `<meta>` component does something different depending on which of these props is specified.
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ The [built-in browser `<option>` component](https://developer.mozilla.org/en-US/
|
||||
|
||||
#### Props {/*props*/}
|
||||
|
||||
`<option>` supports all [common element props.](/reference/react-dom/components/common#common-props)
|
||||
`<option>` supports all [common element props.](/reference/react-dom/components/common#props)
|
||||
|
||||
Additionally, `<option>` supports these props:
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ To display a progress indicator, render the [built-in browser `<progress>`](http
|
||||
|
||||
#### Props {/*props*/}
|
||||
|
||||
`<progress>` supports all [common element props.](/reference/react-dom/components/common#common-props)
|
||||
`<progress>` supports all [common element props.](/reference/react-dom/components/common#props)
|
||||
|
||||
Additionally, `<progress>` supports these props:
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ To add inline or external scripts to your document, render the [built-in browser
|
||||
|
||||
#### Props {/*props*/}
|
||||
|
||||
`<script>` supports all [common element props.](/reference/react-dom/components/common#common-props)
|
||||
`<script>` supports all [common element props.](/reference/react-dom/components/common#props)
|
||||
|
||||
It should have *either* `children` or a `src` prop.
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ To display a select box, render the [built-in browser `<select>`](https://develo
|
||||
|
||||
#### Props {/*props*/}
|
||||
|
||||
`<select>` supports all [common element props.](/reference/react-dom/components/common#common-props)
|
||||
`<select>` supports all [common element props.](/reference/react-dom/components/common#props)
|
||||
|
||||
You can [make a select box controlled](#controlling-a-select-box-with-a-state-variable) by passing a `value` prop:
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ To add inline styles to your document, render the [built-in browser `<style>` co
|
||||
|
||||
#### Props {/*props*/}
|
||||
|
||||
`<style>` supports all [common element props.](/reference/react-dom/components/common#common-props)
|
||||
`<style>` supports all [common element props.](/reference/react-dom/components/common#props)
|
||||
|
||||
* `children`: a string, required. The contents of the stylesheet.
|
||||
* `precedence`: a string. Tells React where to rank the `<style>` DOM node relative to others in the document `<head>`, which determines which stylesheet can override the other. React will infer that precedence values it discovers first are "lower" and precedence values it discovers later are "higher". Many style systems can work fine using a single precedence value because style rules are atomic. Stylesheets with the same precedence go together whether they are `<link>` or inline `<style>` tags or loaded using [`preinit`](/reference/react-dom/preinit) functions.
|
||||
|
||||
@@ -30,7 +30,7 @@ To display a text area, render the [built-in browser `<textarea>`](https://devel
|
||||
|
||||
#### Props {/*props*/}
|
||||
|
||||
`<textarea>` supports all [common element props.](/reference/react-dom/components/common#common-props)
|
||||
`<textarea>` supports all [common element props.](/reference/react-dom/components/common#props)
|
||||
|
||||
You can [make a text area controlled](#controlling-a-text-area-with-a-state-variable) by passing a `value` prop:
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ To specify the title of the document, render the [built-in browser `<title>` com
|
||||
|
||||
#### Props {/*props*/}
|
||||
|
||||
`<title>` supports all [common element props.](/reference/react-dom/components/common#common-props)
|
||||
`<title>` supports all [common element props.](/reference/react-dom/components/common#props)
|
||||
|
||||
* `children`: `<title>` accepts only text as a child. This text will become the title of the document. You can also pass your own components as long as they only render text.
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ A portal only changes the physical placement of the DOM node. In every other way
|
||||
|
||||
* `domNode`: Some DOM node, such as those returned by `document.getElementById()`. The node must already exist. Passing a different DOM node during an update will cause the portal content to be recreated.
|
||||
|
||||
* **optional** `key`: A unique string or number to be used as the portal's [key.](/learn/rendering-lists#keeping-list-items-in-order-with-key)
|
||||
* **optional** `key`: A unique string or number to be used as the portal's [key.](/learn/rendering-lists/#keeping-list-items-in-order-with-key)
|
||||
|
||||
#### Returns {/*returns*/}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ These APIs can be imported from your components. They are rarely used:
|
||||
|
||||
These APIs can be used to make apps faster by pre-loading resources such as scripts, stylesheets, and fonts as soon as you know you need them, for example before navigating to another page where the resources will be used.
|
||||
|
||||
[React-based frameworks](/learn/creating-a-react-app) frequently handle resource loading for you, so you might not have to call these APIs yourself. Consult your framework's documentation for details.
|
||||
[React-based frameworks](/learn/start-a-new-react-project) frequently handle resource loading for you, so you might not have to call these APIs yourself. Consult your framework's documentation for details.
|
||||
|
||||
* [`prefetchDNS`](/reference/react-dom/prefetchDNS) lets you prefetch the IP address of a DNS domain name that you expect to connect to.
|
||||
* [`preconnect`](/reference/react-dom/preconnect) lets you connect to a server you expect to request resources from, even if you don't know what resources you'll need yet.
|
||||
@@ -48,6 +48,6 @@ These APIs were removed in React 19:
|
||||
* [`findDOMNode`](https://18.react.dev/reference/react-dom/findDOMNode): see [alternatives](https://18.react.dev/reference/react-dom/findDOMNode#alternatives).
|
||||
* [`hydrate`](https://18.react.dev/reference/react-dom/hydrate): use [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) instead.
|
||||
* [`render`](https://18.react.dev/reference/react-dom/render): use [`createRoot`](/reference/react-dom/client/createRoot) instead.
|
||||
* [`unmountComponentAtNode`](https://18.react.dev/reference/react-dom/unmountComponentAtNode): use [`root.unmount()`](/reference/react-dom/client/createRoot#root-unmount) instead.
|
||||
* [`unmountComponentAtNode`](/reference/react-dom/unmountComponentAtNode): use [`root.unmount()`](/reference/react-dom/client/createRoot#root-unmount) instead.
|
||||
* [`renderToNodeStream`](https://18.react.dev/reference/react-dom/server/renderToNodeStream): use [`react-dom/server`](/reference/react-dom/server) APIs instead.
|
||||
* [`renderToStaticNodeStream`](https://18.react.dev/reference/react-dom/server/renderToStaticNodeStream): use [`react-dom/server`](/reference/react-dom/server) APIs instead.
|
||||
|
||||
@@ -4,7 +4,7 @@ title: preinit
|
||||
|
||||
<Note>
|
||||
|
||||
[React-based frameworks](/learn/creating-a-react-app) frequently handle resource loading for you, so you might not have to call this API yourself. Consult your framework's documentation for details.
|
||||
[React-based frameworks](/learn/start-a-new-react-project) frequently handle resource loading for you, so you might not have to call this API yourself. Consult your framework's documentation for details.
|
||||
|
||||
</Note>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ title: preinitModule
|
||||
|
||||
<Note>
|
||||
|
||||
[React-based frameworks](/learn/creating-a-react-app) frequently handle resource loading for you, so you might not have to call this API yourself. Consult your framework's documentation for details.
|
||||
[React-based frameworks](/learn/start-a-new-react-project) frequently handle resource loading for you, so you might not have to call this API yourself. Consult your framework's documentation for details.
|
||||
|
||||
</Note>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ title: preload
|
||||
|
||||
<Note>
|
||||
|
||||
[React-based frameworks](/learn/creating-a-react-app) frequently handle resource loading for you, so you might not have to call this API yourself. Consult your framework's documentation for details.
|
||||
[React-based frameworks](/learn/start-a-new-react-project) frequently handle resource loading for you, so you might not have to call this API yourself. Consult your framework's documentation for details.
|
||||
|
||||
</Note>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ title: preloadModule
|
||||
|
||||
<Note>
|
||||
|
||||
[React-based frameworks](/learn/creating-a-react-app) frequently handle resource loading for you, so you might not have to call this API yourself. Consult your framework's documentation for details.
|
||||
[React-based frameworks](/learn/start-a-new-react-project) frequently handle resource loading for you, so you might not have to call this API yourself. Consult your framework's documentation for details.
|
||||
|
||||
</Note>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ title: Server React DOM APIs
|
||||
|
||||
<Intro>
|
||||
|
||||
The `react-dom/server` APIs let you server-side render React components to HTML. These APIs are only used on the server at the top level of your app to generate the initial HTML. A [framework](/learn/creating-a-react-app#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
|
||||
The `react-dom/server` APIs let you server-side render React components to HTML. These APIs are only used on the server at the top level of your app to generate the initial HTML. A [framework](/learn/start-a-new-react-project#production-grade-react-frameworks) may call them for you. Most of your components don't need to import or use them.
|
||||
|
||||
</Intro>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ title: Static React DOM APIs
|
||||
|
||||
<Intro>
|
||||
|
||||
The `react-dom/static` APIs let you generate static HTML for React components. They have limited functionality compared to the streaming APIs. A [framework](/learn/creating-a-react-app#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
|
||||
The `react-dom/static` APIs let you generate static HTML for React components. They have limited functionality compared to the streaming APIs. A [framework](/learn/start-a-new-react-project#production-grade-react-frameworks) may call them for you. Most of your components don't need to import or use them.
|
||||
|
||||
</Intro>
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ In the future, CSS libraries may add built-in animations using View Transition C
|
||||
|
||||
#### Caveats {/*caveats*/}
|
||||
|
||||
- By default, `setState` updates immediately and does not activate `<ViewTransition>`, only updates wrapped in a [Transition](/reference/react/useTransition). You can also use [`<Suspense>`](/reference/react/Suspense) to opt-in to a Transition to [reveal content](/reference/react/Suspense#revealing-content-together-at-once).
|
||||
- By default, `setState` updates immediately and does not activate `<ViewTransition>`, only updates wrapped in a [Transition](/reference/react/useTransition). You can also use [`<Suspense>`](/reference/react/Suspense) to opt-in to a Transition to [reveal content](/link-to-suspense-below).
|
||||
- `<ViewTransition>` creates an image that can be moved around, scaled and cross-faded. Unlike Layout Animations you may have seen in React Native or Motion, this means that not every individual Element inside of it animates its position. This can lead to better performance and a more continuous feeling, smooth animation compared to animating every individual piece. However, it can also lose continuity in things that should be moving by themselves. So you might have to add more `<ViewTransition>` boundaries manually as a result.
|
||||
- Many users may prefer not having animations on the page. React doesn't automatically disable animations for this case. We recommend that using the `@media (prefers-reduced-motion)` media query to disable animations or tone them down based on user preference. In the future, CSS libraries may have this built-in to their presets.
|
||||
- Currently, `<ViewTransition>` only works in the DOM. We're working on adding support for React Native and other platforms.
|
||||
|
||||
@@ -57,7 +57,7 @@ If no Owner Stack is available, `null` is returned (see [Troubleshooting: The Ow
|
||||
|
||||
#### Owner Stack vs Component Stack {/*owner-stack-vs-component-stack*/}
|
||||
|
||||
The Owner Stack is different from the Component Stack available in React error handlers like [`errorInfo.componentStack` in `onUncaughtError`](/reference/react-dom/client/hydrateRoot#error-logging-in-production).
|
||||
The Owner Stack is different from the Component Stack available in React error handlers like [`errorInfo.componentStack` in `onUncaughtError`](/reference/react-dom/client/hydrateRoot#show-a-dialog-for-uncaught-errors).
|
||||
|
||||
For example, consider the following code:
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ title: forwardRef
|
||||
|
||||
In React 19, `forwardRef` is no longer necessary. Pass `ref` as a prop instead.
|
||||
|
||||
`forwardRef` will be deprecated in a future release. Learn more [here](/blog/2024/12/05/react-19#ref-as-a-prop).
|
||||
`forwardRef` will be deprecated in a future release. Learn more [here](/blog/2024/04/25/react-19#ref-as-a-prop).
|
||||
|
||||
</Deprecated>
|
||||
|
||||
|
||||
@@ -312,7 +312,7 @@ export default async function App() {
|
||||
}
|
||||
```
|
||||
|
||||
But using `await` in a [Server Component](/reference/rsc/server-components) will block its rendering until the `await` statement is finished. Passing a Promise from a Server Component to a Client Component prevents the Promise from blocking the rendering of the Server Component.
|
||||
But using `await` in a [Server Component](/reference/react/components#server-components) will block its rendering until the `await` statement is finished. Passing a Promise from a Server Component to a Client Component prevents the Promise from blocking the rendering of the Server Component.
|
||||
|
||||
</DeepDive>
|
||||
|
||||
|
||||
@@ -896,7 +896,7 @@ In this example, a cleanup function is not needed because the `MapWidget` class
|
||||
|
||||
### Fetching data with Effects {/*fetching-data-with-effects*/}
|
||||
|
||||
You can use an Effect to fetch data for your component. Note that [if you use a framework,](/learn/creating-a-react-app#full-stack-frameworks) using your framework's data fetching mechanism will be a lot more efficient than writing Effects manually.
|
||||
You can use an Effect to fetch data for your component. Note that [if you use a framework,](/learn/start-a-new-react-project#production-grade-react-frameworks) using your framework's data fetching mechanism will be a lot more efficient than writing Effects manually.
|
||||
|
||||
If you want to fetch data from an Effect manually, your code might look like this:
|
||||
|
||||
@@ -1048,7 +1048,7 @@ Writing `fetch` calls inside Effects is a [popular way to fetch data](https://ww
|
||||
|
||||
This list of downsides is not specific to React. It applies to fetching data on mount with any library. Like with routing, data fetching is not trivial to do well, so we recommend the following approaches:
|
||||
|
||||
- **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.
|
||||
- **If you use a [framework](/learn/start-a-new-react-project#production-grade-react-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 [React Query](https://tanstack.com/query/latest/), [useSWR](https://swr.vercel.app/), and [React Router 6.4+.](https://beta.reactrouter.com/en/main/start/overview) You can build your own solution too, in which case you would use Effects under the hood but also add logic for deduplicating requests, caching responses, and avoiding network waterfalls (by preloading data or hoisting data requirements to routes).
|
||||
|
||||
You can continue fetching data directly in Effects if neither of these approaches suit you.
|
||||
@@ -1733,7 +1733,7 @@ function Page({ url, shoppingCart }) {
|
||||
|
||||
### Displaying different content on the server and the client {/*displaying-different-content-on-the-server-and-the-client*/}
|
||||
|
||||
If your app uses server rendering (either [directly](/reference/react-dom/server) or via a [framework](/learn/creating-a-react-app#full-stack-frameworks)), your component will render in two different environments. On the server, it will render to produce the initial HTML. On the client, React will run the rendering code again so that it can attach your event handlers to that HTML. This is why, for [hydration](/reference/react-dom/client/hydrateRoot#hydrating-server-rendered-html) to work, your initial render output must be identical on the client and the server.
|
||||
If your app uses server rendering (either [directly](/reference/react-dom/server) or via a [framework](/learn/start-a-new-react-project#production-grade-react-frameworks)), your component will render in two different environments. On the server, it will render to produce the initial HTML. On the client, React will run the rendering code again so that it can attach your event handlers to that HTML. This is why, for [hydration](/reference/react-dom/client/hydrateRoot#hydrating-server-rendered-html) to work, your initial render output must be identical on the client and the server.
|
||||
|
||||
In rare cases, you might need to display different content on the client. For example, if your app reads some data from [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage), it can't possibly do that on the server. Here is how you could implement this:
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ function useCSS(rule) {
|
||||
|
||||
#### How is this better than injecting styles during rendering or useLayoutEffect? {/*how-is-this-better-than-injecting-styles-during-rendering-or-uselayouteffect*/}
|
||||
|
||||
If you insert styles during rendering and React is processing a [non-blocking update,](/reference/react/useTransition#perform-non-blocking-updates-with-actions) the browser will recalculate the styles every single frame while rendering a component tree, which can be **extremely slow.**
|
||||
If you insert styles during rendering and React is processing a [non-blocking update,](/reference/react/useTransition#marking-a-state-update-as-a-non-blocking-transition) the browser will recalculate the styles every single frame while rendering a component tree, which can be **extremely slow.**
|
||||
|
||||
`useInsertionEffect` is better than inserting styles during [`useLayoutEffect`](/reference/react/useLayoutEffect) or [`useEffect`](/reference/react/useEffect) because it ensures that by the time other Effects run in your components, the `<style>` tags have already been inserted. Otherwise, layout calculations in regular Effects would be wrong due to outdated styles.
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ Directives are for use in [React Server Components](/reference/rsc/server-compon
|
||||
|
||||
<Intro>
|
||||
|
||||
Directives provide instructions to [bundlers compatible with React Server Components](/learn/creating-a-react-app#full-stack-frameworks).
|
||||
Directives provide instructions to [bundlers compatible with React Server Components](/learn/start-a-new-react-project#full-stack-frameworks).
|
||||
|
||||
</Intro>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ title: Server Components
|
||||
|
||||
<RSC>
|
||||
|
||||
Server Components are for use in [React Server Components](/learn/creating-a-react-app#full-stack-frameworks).
|
||||
Server Components are for use in [React Server Components](/learn/start-a-new-react-project#full-stack-frameworks).
|
||||
|
||||
</RSC>
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ function UpdateName() {
|
||||
|
||||
When using `useActionState` with Server Functions, React will also automatically replay form submissions entered before hydration finishes. This means users can interact with your app even before the app has hydrated.
|
||||
|
||||
For more, see the docs for [`useActionState`](/reference/react/useActionState).
|
||||
For more, see the docs for [`useActionState`](/reference/react-dom/hooks/useFormState).
|
||||
|
||||
### Progressive enhancement with `useActionState` {/*progressive-enhancement-with-useactionstate*/}
|
||||
|
||||
@@ -219,4 +219,4 @@ function UpdateName() {
|
||||
|
||||
When the <CodeStep step={2}>permalink</CodeStep> is provided to `useActionState`, React will redirect to the provided URL if the form is submitted before the JavaScript bundle loads.
|
||||
|
||||
For more, see the docs for [`useActionState`](/reference/react/useActionState).
|
||||
For more, see the docs for [`useActionState`](/reference/react-dom/hooks/useFormState).
|
||||
|
||||
@@ -41,7 +41,7 @@ export default function RichTextEditor({ timestamp, text }) {
|
||||
}
|
||||
```
|
||||
|
||||
When a file marked with `'use client'` is imported from a Server Component, [compatible bundlers](/learn/creating-a-react-app#full-stack-frameworks) will treat the module import as a boundary between server-run and client-run code.
|
||||
When a file marked with `'use client'` is imported from a Server Component, [compatible bundlers](/learn/start-a-new-react-project#full-stack-frameworks) will treat the module import as a boundary between server-run and client-run code.
|
||||
|
||||
As dependencies of `RichTextEditor`, `formatDate` and `Button` will also be evaluated on the client regardless of whether their modules contain a `'use client'` directive. Note that a single module may be evaluated on the server when imported from server code and on the client when imported from client code.
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ Notably, these are not supported:
|
||||
* Events from event handlers
|
||||
|
||||
|
||||
Supported serializable return values are the same as [serializable props](/reference/rsc/use-client#serializable-types) for a boundary Client Component.
|
||||
Supported serializable return values are the same as [serializable props](/reference/rsc/use-client#passing-props-from-server-to-client-components) for a boundary Client Component.
|
||||
|
||||
|
||||
## Usage {/*usage*/}
|
||||
|
||||
Reference in New Issue
Block a user