diff --git a/scripts/deadLinkChecker.js b/scripts/deadLinkChecker.js index e659772e6..349231b1d 100644 --- a/scripts/deadLinkChecker.js +++ b/scripts/deadLinkChecker.js @@ -11,6 +11,10 @@ const fileCache = new Map(); const anchorMap = new Map(); // Map> const contributorMap = new Map(); // Map <<<<<<< HEAD +<<<<<<< HEAD +======= +const redirectMap = new Map(); // Map +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 ======= const redirectMap = new Map(); // Map >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 @@ -167,7 +171,10 @@ async function validateLink(link) { } <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 // Check for redirects if (redirectMap.has(urlWithoutAnchor)) { const redirectDestination = redirectMap.get(urlWithoutAnchor); @@ -184,6 +191,9 @@ async function validateLink(link) { return validateLink(redirectedLink); } +<<<<<<< HEAD +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 // Check if it's an error code link const errorCodeMatch = urlWithoutAnchor.match(/^\/errors\/(\d+)$/); @@ -318,8 +328,12 @@ async function fetchErrorCodes() { } const codes = await response.json(); errorCodes = new Set(Object.keys(codes)); +<<<<<<< HEAD <<<<<<< HEAD console.log(chalk.gray(`Fetched ${errorCodes.size} React error codes\n`)); +======= + console.log(chalk.gray(`Fetched ${errorCodes.size} React error codes`)); +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 ======= console.log(chalk.gray(`Fetched ${errorCodes.size} React error codes`)); >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 @@ -329,7 +343,10 @@ async function fetchErrorCodes() { } <<<<<<< HEAD +<<<<<<< HEAD +======= ======= +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 async function buildRedirectsMap() { try { const vercelConfigPath = path.join(__dirname, '../vercel.json'); @@ -354,6 +371,9 @@ async function buildRedirectsMap() { } } +<<<<<<< HEAD +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 async function main() { const files = getMarkdownFiles(); @@ -361,6 +381,10 @@ async function main() { await fetchErrorCodes(); <<<<<<< HEAD +<<<<<<< HEAD +======= + await buildRedirectsMap(); +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 ======= await buildRedirectsMap(); >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 @@ -374,6 +398,10 @@ async function main() { if (deadLinks.length > 0) { <<<<<<< HEAD +<<<<<<< HEAD +======= + console.log('\n'); +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 ======= console.log('\n'); >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 diff --git a/src/content/learn/add-react-to-an-existing-project.md b/src/content/learn/add-react-to-an-existing-project.md index b0638e413..f3fc43d2c 100644 --- a/src/content/learn/add-react-to-an-existing-project.md +++ b/src/content/learn/add-react-to-an-existing-project.md @@ -24,11 +24,15 @@ Here's how we recommend to set it up: 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. +<<<<<<< HEAD <<<<<<< HEAD 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/build-a-react-app-from-scratch#consider-using-a-framework) baked into those frameworks. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +This ensures the React part of your app can [benefit from the best practices](/learn/build-a-react-app-from-scratch#consider-using-a-framework) baked into those frameworks. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 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. diff --git a/src/content/learn/synchronizing-with-effects.md b/src/content/learn/synchronizing-with-effects.md index 6ba18f443..633fd04f9 100644 --- a/src/content/learn/synchronizing-with-effects.md +++ b/src/content/learn/synchronizing-with-effects.md @@ -732,11 +732,15 @@ 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: +<<<<<<< HEAD <<<<<<< HEAD - **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#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. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +- **If you use a [framework](/learn/start-a-new-react-project#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. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 - **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. diff --git a/src/content/learn/typescript.md b/src/content/learn/typescript.md index 3ce753069..58bca60e9 100644 --- a/src/content/learn/typescript.md +++ b/src/content/learn/typescript.md @@ -20,11 +20,15 @@ TypeScript is a popular way to add type definitions to JavaScript codebases. Out ## Installation {/*installation*/} +<<<<<<< HEAD <<<<<<< HEAD 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#full-stack-frameworks) offer support for using TypeScript. Follow the framework specific guide for installation: >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +All [production-grade React frameworks](/learn/start-a-new-react-project#full-stack-frameworks) offer support for using TypeScript. Follow the framework specific guide for installation: +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 - [Next.js](https://nextjs.org/docs/app/building-your-application/configuring/typescript) - [Remix](https://remix.run/docs/en/1.19.2/guides/typescript) diff --git a/src/content/learn/you-might-not-need-an-effect.md b/src/content/learn/you-might-not-need-an-effect.md index aa3eb131a..a683be1f4 100644 --- a/src/content/learn/you-might-not-need-an-effect.md +++ b/src/content/learn/you-might-not-need-an-effect.md @@ -26,11 +26,15 @@ 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. +<<<<<<< HEAD <<<<<<< HEAD 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#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than writing Effects directly in your components. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +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#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than writing Effects directly in your components. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 To help you gain the right intuition, let's look at some common concrete examples! @@ -761,11 +765,15 @@ 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). +<<<<<<< HEAD <<<<<<< HEAD **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#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than fetching data in Effects.** >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +**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#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than fetching data in Effects.** +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 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: diff --git a/src/content/reference/react-dom/client/createRoot.md b/src/content/reference/react-dom/client/createRoot.md index da1bfe99e..7097f65e7 100644 --- a/src/content/reference/react-dom/client/createRoot.md +++ b/src/content/reference/react-dom/client/createRoot.md @@ -209,11 +209,15 @@ When your HTML is empty, the user sees a blank page until the app's JavaScript c
``` +<<<<<<< HEAD <<<<<<< HEAD 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#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).* >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +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#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).* +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 diff --git a/src/content/reference/react-dom/client/index.md b/src/content/reference/react-dom/client/index.md index 8f47b2f4b..d76d33d5f 100644 --- a/src/content/reference/react-dom/client/index.md +++ b/src/content/reference/react-dom/client/index.md @@ -4,11 +4,15 @@ title: Client React DOM APIs +<<<<<<< HEAD <<<<<<< HEAD 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#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +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#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 diff --git a/src/content/reference/react-dom/server/index.md b/src/content/reference/react-dom/server/index.md index e25bd9f42..a465d551f 100644 --- a/src/content/reference/react-dom/server/index.md +++ b/src/content/reference/react-dom/server/index.md @@ -4,11 +4,15 @@ title: Server React DOM APIs +<<<<<<< HEAD <<<<<<< HEAD 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#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +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#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 diff --git a/src/content/reference/react-dom/static/index.md b/src/content/reference/react-dom/static/index.md index 739b7bf1d..011adc083 100644 --- a/src/content/reference/react-dom/static/index.md +++ b/src/content/reference/react-dom/static/index.md @@ -4,11 +4,15 @@ title: Static React DOM APIs +<<<<<<< HEAD <<<<<<< HEAD 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#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +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#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 diff --git a/src/content/reference/react-dom/static/prerender.md b/src/content/reference/react-dom/static/prerender.md index ea576d227..a47caffc8 100644 --- a/src/content/reference/react-dom/static/prerender.md +++ b/src/content/reference/react-dom/static/prerender.md @@ -75,6 +75,7 @@ On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD `nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the a nonce value in the prerender itself. ======= `nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the nonce value in the prerender itself. @@ -97,6 +98,9 @@ On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to ======= `nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the nonce value in the prerender itself. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +`nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the nonce value in the prerender itself. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 diff --git a/src/content/reference/react-dom/static/prerenderToNodeStream.md b/src/content/reference/react-dom/static/prerenderToNodeStream.md index 87e75c325..126e29a3b 100644 --- a/src/content/reference/react-dom/static/prerenderToNodeStream.md +++ b/src/content/reference/react-dom/static/prerenderToNodeStream.md @@ -76,6 +76,7 @@ On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD `nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the a nonce value in the prerender itself. ======= `nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the nonce value in the prerender itself. @@ -98,6 +99,9 @@ On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to ======= `nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the nonce value in the prerender itself. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +`nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the nonce value in the prerender itself. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 diff --git a/src/content/reference/react/forwardRef.md b/src/content/reference/react/forwardRef.md index 24e19d9ef..d8068708d 100644 --- a/src/content/reference/react/forwardRef.md +++ b/src/content/reference/react/forwardRef.md @@ -6,6 +6,7 @@ title: forwardRef In React 19, `forwardRef` is no longer necessary. Pass `ref` as a prop instead. +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD `forwardRef` will be deprecated in a future release. Learn more [here](/blog/2024/04/25/react-19#ref-as-a-prop). @@ -15,6 +16,9 @@ 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/04/25/react-19#ref-as-a-prop). >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +`forwardRef` will be deprecated in a future release. Learn more [here](/blog/2024/04/25/react-19#ref-as-a-prop). +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 diff --git a/src/content/reference/react/useEffect.md b/src/content/reference/react/useEffect.md index 6f9b8b0bf..873475f37 100644 --- a/src/content/reference/react/useEffect.md +++ b/src/content/reference/react/useEffect.md @@ -896,11 +896,15 @@ In this example, a cleanup function is not needed because the `MapWidget` class ### Fetching data with Effects {/*fetching-data-with-effects*/} +<<<<<<< HEAD <<<<<<< HEAD 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#full-stack-frameworks) using your framework's data fetching mechanism will be a lot more efficient than writing Effects manually. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +You can use an Effect to fetch data for your component. Note that [if you use a framework,](/learn/start-a-new-react-project#full-stack-frameworks) using your framework's data fetching mechanism will be a lot more efficient than writing Effects manually. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 If you want to fetch data from an Effect manually, your code might look like this: @@ -1052,11 +1056,15 @@ 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: +<<<<<<< HEAD <<<<<<< HEAD - **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#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. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +- **If you use a [framework](/learn/start-a-new-react-project#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. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 - **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. @@ -1741,11 +1749,15 @@ function Page({ url, shoppingCart }) { ### Displaying different content on the server and the client {/*displaying-different-content-on-the-server-and-the-client*/} +<<<<<<< HEAD <<<<<<< HEAD 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#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. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +If your app uses server rendering (either [directly](/reference/react-dom/server) or via a [framework](/learn/start-a-new-react-project#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. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 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: diff --git a/src/content/reference/rsc/directives.md b/src/content/reference/rsc/directives.md index 1a905597e..be75f7506 100644 --- a/src/content/reference/rsc/directives.md +++ b/src/content/reference/rsc/directives.md @@ -10,6 +10,7 @@ Directives are for use in [React Server Components](/reference/rsc/server-compon +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD Directives provide instructions to [bundlers compatible with React Server Components](/learn/start-a-new-react-project#full-stack-frameworks). @@ -19,6 +20,9 @@ Directives provide instructions to [bundlers compatible with React Server Compon ======= Directives provide instructions to [bundlers compatible with React Server Components](/learn/start-a-new-react-project#full-stack-frameworks). >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +Directives provide instructions to [bundlers compatible with React Server Components](/learn/start-a-new-react-project#full-stack-frameworks). +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 diff --git a/src/content/reference/rsc/server-components.md b/src/content/reference/rsc/server-components.md index 1ce6e865a..2ff7ac8d4 100644 --- a/src/content/reference/rsc/server-components.md +++ b/src/content/reference/rsc/server-components.md @@ -4,6 +4,7 @@ title: Server Components +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD Server Components are for use in [React Server Components](/learn/start-a-new-react-project#full-stack-frameworks). @@ -13,6 +14,9 @@ Server Components are for use in [React Server Components](/learn/creating-a-rea ======= Server Components are for use in [React Server Components](/learn/start-a-new-react-project#full-stack-frameworks). >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +Server Components are for use in [React Server Components](/learn/start-a-new-react-project#full-stack-frameworks). +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 diff --git a/src/content/reference/rsc/server-functions.md b/src/content/reference/rsc/server-functions.md index 56c7daf40..b5b4ba3b5 100644 --- a/src/content/reference/rsc/server-functions.md +++ b/src/content/reference/rsc/server-functions.md @@ -35,6 +35,7 @@ To support Server Functions as a bundler or framework, we recommend pinning to a <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD When a Server Function is defined with the [`"use server"`](/reference/rsc/use-server) directive, your framework will automatically create a reference to the server function, and pass that reference to the Client Component. When that function is called on the client, React will send a request to the server to execute the function, and return the result. ======= When a Server Function is defined with the [`"use server"`](/reference/rsc/use-server) directive, your framework will automatically create a reference to the Server Function, and pass that reference to the Client Component. When that function is called on the client, React will send a request to the server to execute the function, and return the result. @@ -57,6 +58,9 @@ When a Server Function is defined with the [`"use server"`](/reference/rsc/use-s ======= When a Server Function is defined with the [`"use server"`](/reference/rsc/use-server) directive, your framework will automatically create a reference to the Server Function, and pass that reference to the Client Component. When that function is called on the client, React will send a request to the server to execute the function, and return the result. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +When a Server Function is defined with the [`"use server"`](/reference/rsc/use-server) directive, your framework will automatically create a reference to the Server Function, and pass that reference to the Client Component. When that function is called on the client, React will send a request to the server to execute the function, and return the result. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 Server Functions can be created in Server Components and passed as props to Client Components, or they can be imported and used in Client Components. diff --git a/src/content/reference/rsc/use-client.md b/src/content/reference/rsc/use-client.md index c783fa571..2e02f91c2 100644 --- a/src/content/reference/rsc/use-client.md +++ b/src/content/reference/rsc/use-client.md @@ -41,6 +41,7 @@ export default function RichTextEditor({ timestamp, text }) { } ``` +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD 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. @@ -50,6 +51,9 @@ When a file marked with `'use client'` is imported from a Server Component, [com ======= 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. >>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 +======= +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. +>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9 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.