useMap
A hook that can manage the state of Map.
Overview
A hook that can manage the state of Map.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMap.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMap.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMap.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMap.jsonA hook that can manage the state of Map.
Examples
Default usage
API
const [
map,
{
set,
setAll,
remove,
reset,
get
}
] = useMap<K, V>(initialValue);Result
| Property | Description | Type |
|---|---|---|
| map | Map object | Map<K, V> |
| set | Add item | (key: K, value: V) => void |
| get | Get item | (key: K) => V | undefined |
| setAll | Set a new Map | (newMap: Iterable<[K, V]>) => void |
| remove | Remove key | (key: K) => void |
| reset | Reset to default | () => void |
Params
| Property | Description | Type | Default |
|---|---|---|---|
| initialValue | Optional, set default value | Iterable<[K, V]> | - |