/** * useSelection (API §9) — the nearest selection scope's value (ids/nodes/anchor + * has/set/add/toggle/clear). Throws outside a ``. */ import { useContext } from 'react' import type { Selection } from './scope.context.js' import { SelectionContext } from './scope.context.js' /** The nearest selection scope. Throws outside a ``. */ export function useSelection(): Selection { const selection = useContext(SelectionContext) if (selection === null) { throw new Error('useSelection must be used within a ') } return selection }