Unverified Commit c1aa8ddf authored by Delba de Oliveira's avatar Delba de Oliveira Committed by GitHub

Docs: Clarify `AbortController.signal` usage in React `fetch` memoization (#63009)

As per @SukkaW's feedback. Closes:
https://linear.app/vercel/issue/DX-2379/clarify-abortcontrollersignal-usage-in-react-fetch-memoization
parent c9cf8b95
...@@ -43,7 +43,7 @@ React extends the [`fetch` API](#fetch) to automatically **memoize** requests th ...@@ -43,7 +43,7 @@ React extends the [`fetch` API](#fetch) to automatically **memoize** requests th
height="857" height="857"
/> />
For example, if you need to use the same data across a route (e.g. in a Layout, Page, and multiple components), you do not have to fetch data at the top of the tree then forward props between components. Instead, you can fetch data in the components that need it without worrying about the performance implications of making multiple requests across the network for the same data. For example, if you need to use the same data across a route (e.g. in a Layout, Page, and multiple components), you do not have to fetch data at the top of the tree, and forward props between components. Instead, you can fetch data in the components that need it without worrying about the performance implications of making multiple requests across the network for the same data.
```tsx filename="app/example.tsx" switcher ```tsx filename="app/example.tsx" switcher
async function getItem() { async function getItem() {
...@@ -109,7 +109,9 @@ Since the memoization is not shared across server requests and only applies duri ...@@ -109,7 +109,9 @@ Since the memoization is not shared across server requests and only applies duri
### Opting out ### Opting out
To opt out of memoization in `fetch` requests, you can pass an `AbortController` `signal` to the request. Memoization only applies to the `GET` method in `fetch` requests, other methods, such as `POST` and `DELETE`, are not memoized. This default behavior is a React optimization and we do not recommend opting out of it.
To manage individual requests, you can use the [`signal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal) property from [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). However, this will not opt requests out of memoization, rather, abort in-flight requests.
```js filename="app/example.js" ```js filename="app/example.js"
const { signal } = new AbortController() const { signal } = new AbortController()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment