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.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useSetState.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useSetState.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useSetState.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useSetState.jsonuseSetState 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 | - |