Quick Start
Installation
Tip
@silver-formily/reactive-react is migrated from @formily/[email protected].
Warning
- Peer dependencies are
react/react-dom^18 || ^19 - ESM-only output.
bash
pnpm add @silver-formily/reactive-react @silver-formily/reactive react react-dombash
npm install @silver-formily/reactive-react @silver-formily/reactive react react-domQuick Start
tsx
import { observable } from '@silver-formily/reactive'
import { observer } from '@silver-formily/reactive-react'
const state = observable({ count: 0 })
const Counter = observer(() => (
<button onClick={() => state.count++}>{state.count}</button>
))Components wrapped with observer collect the reactive fields they read on every render. When a field changes, only the components that depend on it re-render.
Choosing an API
- Reactive rendering: prefer
observer; useObserverfor a JSX subtree. - Derived values:
useComputedreturns an expression's result. Declare props/state inputs throughdeps. - Side effects:
useAutorunEffectruns automatically;useReactionWatchwatches value changes. - See the API reference for React 18/19 refs and subscription lifecycles.
useComputedno longer acceptsfireImmediately;useReactionWatchstill supports it.