# Pause screens you can't see (https://effetch-query.monarcode.dev/docs/react/pause)

Some screens stay mounted while you can't see them: the tabs you aren't
on, the screens a stack navigator keeps under the one in front, a panel
that's hidden rather than removed. Their components still read their
queries, so the queries stay in use: they refetch on every invalidation,
and on focus when they're stale, and the components re-render out of
sight. Pass `paused` while the screen is hidden.

The examples import `todos.ts` from [Getting started](https://effetch-query.monarcode.dev/docs/getting-started).

## Pause a hidden screen

Here a React Navigation screen pauses while it's not focused. The example
declares `useIsFocused`, which your app imports from
`@react-navigation/native`:

```tsx
import * as AsyncResult from "effect/reactivity/AsyncResult";

import { useQuery } from "@monarcode/effetch-query/react";

import { todos } from "./todos.js";

// From @react-navigation/native.
declare function useIsFocused(): boolean;

export function TodoCount() {
  const isFocused = useIsFocused();
  const list = useQuery(todos(), { paused: !isFocused });

  return <>{AsyncResult.getOrElse(list, () => []).length} todos</>;
}
```

A query is in use while something subscribes to it, such as a mounted
component that reads it: see
[Queries in use](https://effetch-query.monarcode.dev/docs/queries/freshness#queries-in-use). A paused reader
doesn't subscribe, so it doesn't count. It keeps showing what it had, and an invalidation,
focus, reconnect or `refetchInterval` doesn't refetch the query for it,
nor re-render the component.

When the screen comes back, the query refetches if it's stale or failed,
as [the mount policy](https://effetch-query.monarcode.dev/docs/queries/freshness#the-mount-policy) does when a
component mounts, unless another reader fetched it
meanwhile and it's still fresh.

## What a paused reader shows

A paused reader shows what it had, with a few rules:

- **What it shows isn't `waiting`,** since nothing fetches for it. A
  placeholder stays a placeholder until it resumes.
- **Paused from its first render,** a reader shows what the cache has,
  without fetching.
- **A query whose readers are all paused isn't in use,** so it's dropped
  after `gcTime` like any other, though the paused readers still show what
  they had.
- **A [`clear`](https://effetch-query.monarcode.dev/docs/cache) replaces what they show** with what the cache
  has, usually nothing, so the screen shows `Initial`.
- **`useQueryState`'s `refetch` resolves at once** for a query that only
  paused readers use, since a paused reader isn't a use.

## Which hooks take paused

`useQuery`, `useQueryState`, `useQueries` and `useInfiniteQuery` take
`paused`. `useInfiniteQuery`'s page functions still fetch pages when
called: see [Load more](https://effetch-query.monarcode.dev/docs/queries/infinite#load-more).
`useSuspenseQuery` doesn't take it.

## What's next

- [React Native](https://effetch-query.monarcode.dev/docs/react/react-native): the signals a React Native app
  needs, and the screens its navigators keep.
- [Freshness and refetching](https://effetch-query.monarcode.dev/docs/queries/freshness): what refetches a
  query in use.
- [Load more](https://effetch-query.monarcode.dev/docs/queries/infinite#load-more): page functions on a paused
  infinite query.