# Show a placeholder (https://effetch-query.monarcode.dev/docs/queries/placeholders)

A todo's detail page can show what the list already has, its title and
whether it's done, while the full todo loads. A placeholder is that value:
something to show until the query's own fetch settles. This page shows how
to give a query one, and what a placeholder is and isn't.

The example imports `todos.ts` from
[Getting started](https://effetch-query.monarcode.dev/docs/getting-started), and `entities.ts` from
[Entities](https://effetch-query.monarcode.dev/docs/cache/entities).

## Give a query a placeholder

`placeholder` returns `Option.some` of a value to show, or `Option.none()`
for nothing. On `api.query`, it gets the call's `params` and `query`. Here
is `todo` from `todos.ts` with one. In your app, it replaces the `todo`
that `todos.ts` defines:

```ts
import { Entity } from "@monarcode/effetch-query";

import { Todos } from "./entities.js";
import { api, getTodo } from "./todos.js";

export const todo = api.query(getTodo, {
  staleTime: "1 minute",
  // A list's copy, if one is cached, until the todo's own fetch settles.
  placeholder: ({ params }) => Entity.get(Todos, Number(params.id)),
});
```

`Entity.get` reads the newest cached copy of the todo, from any cached
query whose schema holds todos, such as the list. Any Effect that reads
the cache works, such as `Query.get` of a list. On `Query.make`,
`placeholder` is an Effect, and on `Query.family` a function of the
member's argument.

Keep it synchronous, reading the cache. An asynchronous one shows only
after it's done, if the fetch hasn't settled first, and a suspense reader
that's already suspended doesn't get it: it waits for the fetch. If a
placeholder dies, the defect is logged and nothing shows.

## What a placeholder is

A placeholder is shown, never cached. It shows as a waiting `Success`, so
a component renders it as it would the value, and `useSuspenseQuery`
doesn't suspend on it. When the fetch settles, its value or its failure
replaces the placeholder.

Since it isn't cached:

- `Query.get`, `Query.update` and `Query.fetch` don't see it;
- `QueryClient.dehydrate` doesn't send it, and a server render doesn't
  show it;
- a query that reads this one through `ctx.result` waits for the real
  value.

After `Query.reset`, the placeholder shows again until the next fetch
settles.

## Tell a placeholder from a value

Sometimes a component needs to know which one it shows: an edit form
shouldn't open on the list's copy of a todo. `useQueryState` returns an
`isPlaceholder` flag for this. [Read a query as an object](https://effetch-query.monarcode.dev/docs/react/as-object)
shows it, and how it works with `keepPrevious` and `paused`.

## What's next

- [Entities](https://effetch-query.monarcode.dev/docs/cache/entities): find one record's copies across every
  cached query.
- [Read a query as an object](https://effetch-query.monarcode.dev/docs/react/as-object): tell a placeholder
  from the query's own value in a component.
- [Suspense and error boundaries](https://effetch-query.monarcode.dev/docs/react/suspense): suspend until a
  query has a value.