Installation
Install Legend-State using your preferred package manager:Basic usage
Create an observable
Create observables to hold your state. Observables can contain any value - primitives, objects, arrays, or even functions.
Observe changes
React to changes with the
observe() function. It runs immediately and whenever tracked observables change.React integration
Legend-State provides powerful React integration with hooks and components for building reactive UIs.Use the observer HOC
The
observer HOC makes components automatically re-render when observables they access change.Use the useObservable hook
Create local component state with
useObservable(). It works just like observables but is scoped to the component.Complete example
Here’s a complete todo list example that demonstrates multiple concepts:Key concepts
Observables
Learn about creating and working with observables
React Hooks
Explore React integration hooks like useObservable and useSelector
Fine-Grained Rendering
Master fine-grained reactivity for maximum performance
Persistence & Sync
Set up automatic persistence and real-time sync
Next steps
Core concepts
Dive deep into observables, computed values, and reactivity
React integration
Learn about all React hooks and components
Sync & persistence
Add local-first sync and persistence to your app
TypeScript guide
Get the most out of TypeScript with Legend-State