shadcn-ahooks

useSet

A hook that can manage the state of Set.

Overview

A hook that can manage the state of Set.

Documentation and Examples

Installation

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

A hook that can manage the state of Set.

Examples

Default usage

API

const [
  set,
  {
    add,
    remove,
    reset
  }
] = useSet<K>(initialValue);

Result

PropertyDescriptionType
setSet objectSet<K>
addAdd item(key: K) => void
removeRemove item(key: K) => void
resetReset to default() => void

Params

PropertyDescriptionTypeDefault
initialValueOptional, set default valueIterable<K>-

On this page