File tree Expand file tree Collapse file tree 2 files changed +17
-38
lines changed
src/tools/StatefulObservable Expand file tree Collapse file tree 2 files changed +17
-38
lines changed Original file line number Diff line number Diff line change 11` StatefulObservable ` is a construct that allow to avoid having to depend on [ EVT] ( https://evt.land ) .
22
3- A ` StatefulObservable ` can be converted to an evt with:
3+ A ` StatefulObservable ` can be used to implement a signal: Wire a non react-land function to a react component.
4+ Example:
45
5- ``` ts
6- import { statefulObservableToStatefulEvt } from " powerhooks/ tools/StatefulObservable/statefulObservableToStatefulEvt " ;
6+ ``` tsx
7+ import { createStatefulObservable , useRerenderOnChange } from " tools/StatefulObservable" ;
78
8- const evtXyz = statefulObservableToStatefulEvt ({
9- " statefulObservable" : $xyz
10- // Optionally you can pass a Ctx
11- });
9+ const $counter = createStatefulObservable (() => 0 );
10+
11+ export function incrementCounter() {
12+ $counter .current ++ ;
13+ }
14+
15+ export function Counter() {
16+ useRerenderOnChange ($counter );
17+
18+ const counter = $counter .current ;
19+
20+ return <span >Counter: { counter } </span >;
21+ }
1222```
1323
1424WARNING: Unlike ` StatefulEvt ` , ` StatefulObservable ` do not post when we first attach.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments