Skip to content

useSet ​

Hook that manages a set structure

utilities
test coverage
Last changed: last month

Installation ​

Library
CLI
Manual
typescript
import { useSet } from '@siberiacancode/reactuse';

Usage ​

typescript
const { value, add, remove, clear, reset, toggle, union, intersection, difference, symmetricDifference, size, has } = useSet([1, 2, 3]);

Demo ​

Api ​

Parameters

NameTypeDefaultNote
values?Value[]-The initial array of the set

Returns

UseSetReturn<Value>

Type declaration ​

typescript
interface UseSetReturn<Value> {
  /** The size of the set */
  size: number;
  /** The current set */
  value: Set<Value>;
  /** Function to add a value to the set */
  add: (value: Value) => void;
  /** Function to clear the set */
  clear: () => void;
  /** Function to get the symmetric difference of two sets */
  difference: (other: Set<Value>) => void;
  /** Function to check if a value exists in the set */
  has: (value: Value) => boolean;
  /** Function to get the difference of two sets */
  intersection: (other: Set<Value>) => void;
  /** Function to remove a value from the set */
  remove: (value: Value) => void;
  /** Function to toggle a value in the set */
  reset: () => void;
  /** Function to get the symmetric difference of two sets */
  symmetricDifference: (other: Set<Value>) => void;
  /** Function to toggle a value in the set */
  toggle: (value: Value) => void;
  /** Function to get the union of two sets */
  union: (other: Set<Value>) => void;
}

Source ​

Source • Demo

Contributors ​

D
debabin
debabin
H
hywax
hywax

Released under the MIT License.