<!-- Generated from hooks/use-viewer-selection.mdx; edit the MDX source. -->

Package: @liveroom-tech/react-immersive
Canonical: https://react-immersive.liveroom.dev/docs/hooks/use-viewer-selection

# `useViewerSelection`

Manages selection state for the viewer. Pass `handleObjectSelect` to `onObjectSelect` and consume `selectedObjectBinding` wherever you need to react to the user's selection.

This hook manages one active binding. Manage a
separate array of `multiSelectedKeys` for group outlines/transforms; use binding
record keys rather than `binding.id`. Handle a null selection callback by
clearing that array, and clear selection when switching models. The hook does
not add checkbox or toggle behavior. See the
[complete multi-select example](https://react-immersive.liveroom.dev/docs/reference/model-viewer#controlled-group-selection-and-playback).

## Usage

```tsx
import { useViewerSelection } from "@liveroom-tech/react-immersive";

const {
  selectedObjectBinding,
  setSelectedObjectBinding,
  handleObjectSelect,
  clearSelection,
} = useViewerSelection();

<ModelViewer
  onObjectSelect={handleObjectSelect}
  selectedObject={selectedObjectBinding}
  ...
/>
```

## Returns

| Name | Type | Description |
|------|------|-------------|
| `selectedObjectBinding` | `ObjectBinding \| null` | The currently selected binding, or `null` |
| `setSelectedObjectBinding` | `(binding: ObjectBinding \| null) => void` | Set selection imperatively |
| `handleObjectSelect` | `(binding: ObjectBinding \| null) => void` | Callback to pass to `onObjectSelect` |
| `clearSelection` | `() => void` | Clears the current selection |
