shadcn-ahooks

useMap

A hook that can manage the state of Map.

Overview

A hook that can manage the state of Map.

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMap.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMap.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMap.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMap.json

A hook that can manage the state of Map.

Examples

Default usage

API

const [
  map,
  {
    set,
    setAll,
    remove,
    reset,
    get
  }
] = useMap<K, V>(initialValue);

Result

PropertyDescriptionType
mapMap objectMap<K, V>
setAdd item(key: K, value: V) => void
getGet item(key: K) => V | undefined
setAllSet a new Map(newMap: Iterable<[K, V]>) => void
removeRemove key(key: K) => void
resetReset to default() => void

Params

PropertyDescriptionTypeDefault
initialValueOptional, set default valueIterable<[K, V]>-

On this page