Founding price: $35, then $99 after 23:59 UTC on 4 November, then $99
Get ProState for a Set with add, delete, toggle, has, clear and reset that always returns a new Set, so React sees the change.
This item has no props to tune. Use the lens above to change theme, density, direction and more.
Use it to track a set of unique ids: selected rows, expanded nodes, active filters or picked tags.
Do not use it when order matters or items repeat; use an array. For range selection with shift-click use useSelection.
import { useSet } from "@/hooks/use-set"const [selected, { toggle, clear, has }] = useSet<string>()useSet<T>(initial?: Iterable<T>): [ReadonlySet<T>, { add, delete, toggle, has, clear, reset, set }]
| Handler | Description |
|---|---|
add(item) | Add an item. Keeps the same Set if it is already there. |
delete(item) | Remove an item. Keeps the same Set if it was not there. |
toggle(item) | Add the item if missing, remove it if present. |
has(item) | Whether the current Set holds the item. |
clear() | Remove everything. |
reset() | Return to the initial items. |
set(items) | Replace the contents. |
The returned Set is never mutated: each change creates a new Set, so it works as a dependency and with React.memo.
A hook has no markup. When it tracks a selection, mirror it with aria-selected or aria-checked on each item.
The hook ships with renderHook tests (use-set.test.ts) covering its behaviour, cleanup on unmount and server-safe defaults. It is safe to render on the server.