# cacheSignal()

> The `cacheSignal()` API in React returns an `AbortSignal` that aborts when the lifetime of the `cache()` scope ends.

## What is cacheSignal in React and how do I cancel fetches?

The API for Server Components that returns an `AbortSignal`, which aborts when rendering is finished or cancelled. Passed to `fetch()` to stop unnecessary work when its result is no longer needed.

- Topic: APIs
- Type: API

## Example

Wrong:

```jsx
const getPost = cache((id) => fetch(`/api/posts/${id}`));
async function Post({ id }) {
  const res = await getPost(id);
  return <Article data={await res.json()} />;
}
```

Right:

```jsx
const getPost = cache((id) => fetch(`/api/posts/${id}`, { signal: cacheSignal() }));
async function Post({ id }) {
  const res = await getPost(id);
  return <Article data={await res.json()} />;
}
```

The fetch is aborted when React no longer needs the result, so an abandoned render does not keep requests running.

## Common mistakes

- Calling `cacheSignal()` in a Client Component and passing its `null` result as if it were a signal.

## Key points

- `cacheSignal()` is called only in Server Components, not in Client Components.
- The returned signal is passed to `fetch` or another API that accepts an `AbortSignal`.
- Code handles a `null` return, which happens when it runs outside of rendering.

## Interview questions

### When does the cacheSignal abort?

When React finishes rendering, when the render is aborted, or when it fails. After that, results of cached work are no longer used.

### Why does cacheSignal() return null?

It returns `null` outside of a server render, for example in a Client Component or in code that runs after rendering.

## Related cards

- [cache()](https://wonderium.dev/react/cache.md)
- [AbortSignal.any()](https://wonderium.dev/js/abort-signal-any.md)
- [AbortController](https://wonderium.dev/js/abort-controller.md)
- [Server Components](https://wonderium.dev/react/server-components.md)
- [fetch()](https://wonderium.dev/js/fetch.md)

---

- Level: [React](https://wonderium.dev/react.md)
- HTML version: https://wonderium.dev/react/cache-signal
- Last updated: 2026-11-25
