# Select part of a value (https://0758e0c7.effetch-query.pages.dev/docs/react/select)

`select` derives what a component shows from a query's value, such as a
count or one field. `useQuery`, `useSuspenseQuery` and `useQueryState`
take it:

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

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

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

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

export function OpenCount() {
  const count = useQuery(todos(), {
    select: (list) => list.filter((todo) => !todo.done).length,
  });
  return <p>{AsyncResult.getOrElse(count, () => 0)} open</p>;
}
```

The component re-renders when the selection changes or a fetch starts or
ends, not for changes the selection doesn't show: a selection equal to
the last one, compared by content (`Equal.equals`), keeps the result it
showed. An inline function runs on every render; for a costly selection,
define it outside the component or with `useCallback`.

The cache keeps the whole value, so other components reading the query
see it unchanged, and the query still refetches on mount, focus and
polling as without `select`. A failure's previous success is selected
too, and with `keepPrevious`, the last selection shown is kept.

A `select` that throws shows as a failure with the defect;
`useSuspenseQuery` throws it to the error boundary as a `QueryFailure`.
The options' types are `UseQuerySelectOptions`, for `useQuery` and
`useQueryState`, and `UseSuspenseQueryOptions`, for `useSuspenseQuery`.