useMap
Manages a reactive Map state with immutable helper actions for setting, deleting, clearing, and querying entries.
Loading preview...
The useMap hook manages a JavaScript Map in React state and provides memoized helper methods (set, setAll, remove, clear, reset, and get) that clone the map on every mutation to trigger re-renders cleanly.
Installation
Usage
Examples
Adding and Removing Key-Value Entries
Use set, remove, and clear to update entries reactively without mutating the underlying Map instance in place.
API Reference
UseMapActions
Memoized map mutation and lookup methods returned as the second tuple element.
Property
Specification
setfunction
Sets or updates the value for
keyFull Signature
Parameters
keyKvalueVsetAllfunction
Replaces the entire map with the provided entries
Full Signature
Parameters
entriesIterable<readonly [K, V]>removefunction
Deletes
key from the map if presentFull Signature
Parameters
keyKclearfunction
Removes all entries from the map
Full Signature
resetfunction
Resets the map back to
initialValueFull Signature
getfunction
Returns the value associated with
key, or undefinedFull Signature
Parameters
keyKhasfunction
Returns
true if key exists in the mapFull Signature
Parameters
keyK