useSet
Manages a reactive Set in React state with immutable update helpers.
Loading preview...
The useSet hook manages a JavaScript Set in React state and provides memoized helper methods (add, remove, toggle, has, clear, and reset) that clone the set on mutations so components re-render predictably.
Installation
Usage
Examples
Multi-Select Tag Filter
Use toggle and has to build a multi-select filter bar where clicking a tag adds or removes it from the active set.
Tracking Expanded Accordion Items
Store expanded item IDs in useSet to allow multiple accordion panels to stay open simultaneously.
API Reference
UseSetActions
Memoized set mutation and lookup methods returned as the second tuple element.
Property
Specification
addfunction
Adds
value to the set if not already present.Full Signature
Parameters
valueTremovefunction
Removes
value from the set if present.Full Signature
Parameters
valueTtogglefunction
Adds
value if absent, or removes it if present.Full Signature
Parameters
valueTclearfunction
Removes all values from the set.
Full Signature
resetfunction
Resets the set back to
initialValue.Full Signature
hasfunction
Returns
true if value is in the set.Full Signature
Parameters
valueT