Skip to Content
HooksuseViewerSelection

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 .

Usage

import { useViewerSelection } from "@liveroom-tech/react-immersive"; const { selectedObjectBinding, setSelectedObjectBinding, handleObjectSelect, clearSelection, } = useViewerSelection(); <ModelViewer onObjectSelect={handleObjectSelect} selectedObject={selectedObjectBinding} ... />

Returns

NameTypeDescription
selectedObjectBindingObjectBinding | nullThe currently selected binding, or null
setSelectedObjectBinding(binding: ObjectBinding | null) => voidSet selection imperatively
handleObjectSelect(binding: ObjectBinding | null) => voidCallback to pass to onObjectSelect
clearSelection() => voidClears the current selection