File tree 2 files changed +17
-38
lines changed
src/tools/StatefulObservable
2 files changed +17
-38
lines changed Original file line number Diff line number Diff line change 1
1
` StatefulObservable ` is a construct that allow to avoid having to depend on [ EVT] ( https://evt.land ) .
2
2
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:
4
5
5
- ``` ts
6
- import { statefulObservableToStatefulEvt } from " powerhooks/ tools/StatefulObservable/statefulObservableToStatefulEvt " ;
6
+ ``` tsx
7
+ import { createStatefulObservable , useRerenderOnChange } from " tools/StatefulObservable" ;
7
8
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
+ }
12
22
```
13
23
14
24
WARNING: 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