useReactive
A React hook from ahooks library
Overview
A React hook from ahooks library
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useReactive.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useReactive.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useReactive.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useReactive.jsonIt offers data reactivity when manipulating states and views, in which case useState is unnecessary for state definition. Modifying properties will automatically lead to view rerendering.
Examples
Default Usage
Array
Computed Properties
Notice
API
const state = useReactive(initialValue: Record<string, any>);Params
| Params | Description | Type | Default |
| | - | ---- |
| initialState | Current state | Record<string, any> | - |
FAQ
When useReactive is used with Map, Set, it will throw an error or not work?
useReactive is not compatible with Map, Set。
Related issues: #2239
useRafTimeout
A hook implements with requestAnimationFrame for better performance. The API is consistent with useTimeout. the advantage is that will not trigger function when the page is not rendering, such as page hiding or minimization.
useResetState
useResetState works similar to React.useState, it provides a reset method