Skip to content

Commit b56c8ae

Browse files
committed
Update StatefulObservable documentation
1 parent 7eee6dd commit b56c8ae

File tree

2 files changed

+17
-38
lines changed

2 files changed

+17
-38
lines changed

src/tools/StatefulObservable/README.md

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
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

1424
WARNING: Unlike `StatefulEvt`, `StatefulObservable` do not post when we first attach.

src/tools/StatefulObservable/statefulObservableToStatefulEvt.ts

-31
This file was deleted.

0 commit comments

Comments
 (0)