Hooks

useSelection

Publisher

cermuel

50 hooks published

More from this publisher

useSelection

Handle single, multiple, and range selection.

useSelection.tsx
import { useSelection } from "@cermuel/hooks/react";export function useSelectionExample() {  const selection = useSelection(['a', 'b', 'c']);  return <p>{selection.selected.size} selected</p>;}

Props

Param
Type
Default Value
items
T[]
getKey?
(item: T) => string
defaultSelectionKey

Returns

{ selected: Set<string>; toggle: (item: T) => void; clear: () => void; selectAll: () => void; isSelected: (item: T) => boolean; }