File tree 1 file changed +11
-11
lines changed
src/frameworks/react/$snippets
1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change 1
1
import "@typescript/lib-dom" ;
2
2
3
3
// #region stopwatch
4
- import { Cell , Resource } from "@starbeam/universal" ;
4
+ import { Cell , Formula , Resource } from "@starbeam/universal" ;
5
5
6
- const Stopwatch = Resource ( ( r ) => {
6
+ const Stopwatch = Resource ( ( { on } ) => {
7
7
const time = Cell ( new Date ( ) ) ;
8
8
9
- r . on . setup ( ( ) => {
10
- const interval = setInterval ( ( ) => {
11
- time . set ( new Date ( ) ) ;
12
- } ) ;
9
+ const interval = setInterval ( ( ) => {
10
+ time . set ( new Date ( ) ) ;
11
+ } ) ;
13
12
13
+ on . cleanup ( ( ) => {
14
14
return ( ) => clearInterval ( interval ) ;
15
15
} ) ;
16
16
17
- return ( ) => {
17
+ return Formula ( ( ) => {
18
18
const now = time . current ;
19
19
20
20
return new Intl . DateTimeFormat ( "en-US" , {
@@ -23,17 +23,17 @@ const Stopwatch = Resource((r) => {
23
23
second : "numeric" ,
24
24
hour12 : false ,
25
25
} ) . format ( now ) ;
26
- } ;
26
+ } ) ;
27
27
} ) ;
28
28
// #endregion stopwatch
29
29
30
30
// #region component
31
- import { useResource } from "@starbeam/react" ;
31
+ import { use } from "@starbeam/react" ;
32
32
33
33
export const Clock = ( ) => {
34
34
// #highlight:next
35
- const time = useResource ( ( ) => Stopwatch ) ;
35
+ const time = use ( ( ) => Stopwatch , [ ] ) ;
36
36
37
- return < div > { time } </ div > ;
37
+ return < div > { time ?? "now" } </ div > ;
38
38
} ;
39
39
// #endregion app
You can’t perform that action at this time.
0 commit comments