shadcn-ahooks

useReactive

A React hook from ahooks library

Overview

A React hook from ahooks library

Documentation and Examples

Installation

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

It 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

On this page