shadcn-ahooks

useSetState

useSetState works similar to this.setState of class component, used to manage the state of object type.

Overview

useSetState works similar to this.setState of class component, used to manage the state of object type.

Documentation and Examples

Installation

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

useSetState works similar to this.setState of class component, used to manage the state of object type.

Examples

Default usage

Updating with callback

API

const [state, setState] = useSetState<T>(initialState);

Result

| Property | Description | Type | Default | | -- | -- | ---- | | initialState | Initial state | T \| () => T | - |

On this page