Skip to content

Commit 0541ac9

Browse files
committed
Fix react example
1 parent 63fb09c commit 0541ac9

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed
+11-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import "@typescript/lib-dom";
22

33
// #region stopwatch
4-
import { Cell, Resource } from "@starbeam/universal";
4+
import { Cell, Formula, Resource } from "@starbeam/universal";
55

6-
const Stopwatch = Resource((r) => {
6+
const Stopwatch = Resource(({ on }) => {
77
const time = Cell(new Date());
88

9-
r.on.setup(() => {
10-
const interval = setInterval(() => {
11-
time.set(new Date());
12-
});
9+
const interval = setInterval(() => {
10+
time.set(new Date());
11+
});
1312

13+
on.cleanup(() => {
1414
return () => clearInterval(interval);
1515
});
1616

17-
return () => {
17+
return Formula(() => {
1818
const now = time.current;
1919

2020
return new Intl.DateTimeFormat("en-US", {
@@ -23,17 +23,17 @@ const Stopwatch = Resource((r) => {
2323
second: "numeric",
2424
hour12: false,
2525
}).format(now);
26-
};
26+
});
2727
});
2828
// #endregion stopwatch
2929

3030
// #region component
31-
import { useResource } from "@starbeam/react";
31+
import { use } from "@starbeam/react";
3232

3333
export const Clock = () => {
3434
// #highlight:next
35-
const time = useResource(() => Stopwatch);
35+
const time = use(() => Stopwatch, []);
3636

37-
return <div>{time}</div>;
37+
return <div>{time ?? "now"}</div>;
3838
};
3939
// #endregion app

0 commit comments

Comments
 (0)