Skip to content

Commit a9b29cc

Browse files
committed
Adding an example for createElement
1 parent ab287a2 commit a9b29cc

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

test/Container.purs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Test.Container where
2+
3+
import Prelude
4+
5+
import React
6+
7+
import qualified React.DOM as D
8+
import qualified React.DOM.Props as P
9+
10+
container = mkUI $ spec unit \ctx -> do
11+
children <- getChildren ctx
12+
13+
let ui = D.div [ P.style { borderColor: "red"
14+
, borderWidth: 2
15+
, padding: 10
16+
}
17+
] children
18+
19+
return ui

test/Main.purs

+14-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ import React
1010
import qualified React.DOM as D
1111
import qualified React.DOM.Props as P
1212

13-
foreign import interval :: forall eff a.
14-
Int ->
13+
import Test.Container (container)
14+
15+
foreign import interval :: forall eff a.
16+
Int ->
1517
Eff eff a ->
1618
Eff eff Unit
1719

1820
hello = mkUI $ spec unit \ctx -> do
1921
props <- getProps ctx
2022
return $ D.h1 [ P.className "Hello"
2123
, P.style { background: "lightgray" }
22-
]
24+
]
2325
[ D.text "Hello, "
2426
, D.text props.name
2527
]
@@ -44,5 +46,13 @@ counter = mkUI counterSpec
4446
]
4547

4648
main = do
47-
let component = D.div' [ hello { name: "World" }, counter unit ]
49+
let component = D.div' [
50+
hello { name: "World" },
51+
counter unit,
52+
createElement container unit [
53+
D.p [] [ D.text "This is line one" ],
54+
D.p [] [ D.text "This is line two" ]
55+
]
56+
]
57+
4858
renderToBody component

0 commit comments

Comments
 (0)