Skip to content

Commit 534f01e

Browse files
authored
README: Example how to mount an application (#45)
1 parent 53dfc60 commit 534f01e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,31 @@
88
</a>
99

1010
This library contains the [React Basic](https://github.com/lumihq/purescript-react-basic) DOM modules.
11+
12+
## Example
13+
14+
```purescript
15+
import Prelude
16+
17+
import Data.Maybe (Maybe(..))
18+
import Effect (Effect)
19+
import Effect.Exception (throw)
20+
import React.Basic.DOM.Client (createRoot, renderRoot)
21+
import React.Basic.DOM (text)
22+
import Web.DOM.NonElementParentNode (getElementById)
23+
import Web.HTML (window)
24+
import Web.HTML.HTMLDocument (toNonElementParentNode)
25+
import Web.HTML.Window (document)
26+
27+
main :: Effect Unit
28+
main = do
29+
doc <- document =<< window
30+
root <- getElementById "root" $ toNonElementParentNode doc
31+
case root of
32+
Nothing -> throw "Could not find container element"
33+
Just container -> do
34+
reactRoot <- createRoot container
35+
renderRoot reactRoot (text "Hello")
36+
```
37+
38+
More examples can be found in the [PureScript Cookbook](https://github.com/JordanMartinez/purescript-cookbook/tree/master/recipes).

0 commit comments

Comments
 (0)