agentskit.js
Hooks

useReactive

Proxy-based fine-grained reactive state. Mutations trigger re-renders only for components that read the changed properties.

Proxy-based fine-grained reactive state. Mutations trigger re-renders only for components that read the changed properties.

Usage

import { useReactive } from '@agentskit/react'

function Counter() {
  const state = useReactive({ count: 0 })

  return (
    <button onClick={() => state.count++}>
      Count: {state.count}
    </button>
  )
}

API

const state = useReactive(initialState)

Parameters

ParamTypeDescription
initialStateRecord<string, unknown>Initial state object

Returns

A proxied version of the state object. Read and write properties directly — writes trigger re-renders.

How It Works

Internally uses useSyncExternalStore to bridge proxy-based tracking with React's reconciliation model. The proxy intercepts property writes and notifies React to re-render.

✎ Edit this page on GitHub·Found a problem? Open an issue →·How to contribute →

On this page