State Management
useNativeMapState
About
Hook to manage native JavaScript Map() object state in React with a comprehensive set of map operations.
Examples
Basic usage
Individual operations
Bulk operations
Arguments
| Argument | Type | Description | Default value | 
|---|---|---|---|
| initialMapState | Map<K, V> | Initial map state | new Map() | 
Return value
Returns an array with the following items:
| Return value | Type | Description | 
|---|---|---|
| map | ReadonlyMap<K, V> | Current map state (read-only) | 
| controls | MapControls<K, V> | Object with methods to manipulate the map | 
Map Controls
| Method | Type | Description | 
|---|---|---|
| set | (key: K, value: V) => void | Set a key-value pair | 
| get | (key: K) => V | undefined | Get value by key | 
| has | (key: K) => boolean | Check if key exists | 
| remove | (key: K) => void | Remove a key-value pair | 
| clear | () => void | Clear all entries | 
| size | () => number | Get number of entries | 
| setMultiple | (entries: [K, V][]) => void | Set multiple key-value pairs | 
| removeMultiple | (keys: K[]) => void | Remove multiple keys | 
| hasSome | (keys: K[]) => boolean | Check if at least one key exists | 
| hasEvery | (keys: K[]) => boolean | Check if all keys exist |