Skip to content

useMap ​

Hook that manages a map structure

utilities
test coverage
Last changed: last month

Installation ​

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

Usage ​

typescript
const { value, set, remove, clear, reset, size, has } = useMap([1, 'one'], [2, 'two']);

Demo ​

Api ​

Parameters

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

Returns

UseMapReturn<Key, Value>

Type declaration ​

typescript
export interface UseMapReturn<Key, Value> {
  /** The size of the map */
  size: number;
  /** The current map */
  value: Map<Key, Value>;
  /** Function to clear the map */
  clear: () => void;
  /** Function to check if a value exists in the map */
  has: (key: Key) => boolean;
  /** Function to remove a value from the map */
  remove: (key: Key) => void;
  /** Function to toggle a value in the map */
  reset: () => void;
  /** Function to add a value to the map */
  set: (key: Key, value: Value) => void;
}

Source ​

Source • Demo

Contributors ​

D
debabin
debabin
H
hywax
hywax

Released under the MIT License.