Examples
Live examples
Run Reactant modules in your browser and see how changes reach the view.
01 · State and actions
Counter
Run an action and watch the view read the new state with useConnector.
- @state
- @action
- useConnector
@injectable({ name: 'counter' })
class Counter {
@state count = 0;
@action
add(step: number) {
this.count += step;
}
} Live previewReactant + React 18
Loading the live example…
02 · Dependency injection
Computed cart
Change the quantity and watch the total derive from state and an injected pricing service.
- @computed
- constructor injection
@injectable({ name: 'cart' })
class Cart {
constructor(public pricing: Pricing) {}
@state quantity = 1;
@computed
get total() {
return this.quantity * this.pricing.unitPrice;
}
} Live previewReactant + React 18
Loading the live example…