@@ -11,28 +11,30 @@ import Data.Newtype (class Newtype)
11
11
import Effect (Effect )
12
12
import Effect.Exception (throw )
13
13
import Effect.Timer (clearInterval , setInterval )
14
- import React.Basic.DOM (render )
15
14
import React.Basic.DOM as R
15
+ import React.Basic.DOM.Client (createRoot , renderRoot )
16
16
import React.Basic.Hooks (Component , Hook , UseEffect , UseState , coerceHook , component , useEffectOnce , useState' , (/\))
17
17
import React.Basic.Hooks as React
18
+ import Web.DOM.NonElementParentNode (getElementById )
18
19
import Web.HTML (window )
19
- import Web.HTML.HTMLDocument (body )
20
- import Web.HTML.HTMLElement (toElement )
20
+ import Web.HTML.HTMLDocument (toNonElementParentNode )
21
21
import Web.HTML.Window (document )
22
22
23
23
type Time = { hours :: Int , minutes :: Int , seconds :: Int }
24
24
25
25
main :: Effect Unit
26
26
main = do
27
- body <- body =<< document =<< window
28
- case body of
29
- Nothing -> throw " Could not find body."
30
- Just b -> do
31
- time <- mkTime
32
- render (time {}) (toElement b)
27
+ doc <- document =<< window
28
+ root <- getElementById " root" $ toNonElementParentNode doc
29
+ case root of
30
+ Nothing -> throw " Could not find root."
31
+ Just container -> do
32
+ reactRoot <- createRoot container
33
+ app <- mkApp
34
+ renderRoot reactRoot (app {})
33
35
34
- mkTime :: Component { }
35
- mkTime = do
36
+ mkApp :: Component { }
37
+ mkApp = do
36
38
now <- JSDate .now >>= getTime
37
39
component " Time" \_ -> React .do
38
40
{ hours, minutes, seconds } <- useCurrentTime now
@@ -48,7 +50,7 @@ mkTime = do
48
50
49
51
newtype UseCurrentTime hooks = UseCurrentTime (UseEffect Unit (UseState Time hooks ))
50
52
51
- derive instance ntUseCurrentTime :: Newtype (UseCurrentTime hooks ) _
53
+ derive instance Newtype (UseCurrentTime hooks ) _
52
54
53
55
useCurrentTime :: Time -> Hook UseCurrentTime Time
54
56
useCurrentTime initialTime =
0 commit comments