DEV Community

Arbaaz
Arbaaz

Posted on • Updated on • Originally published at arbaaz.io

How to append child to body with rescript

Install bs-webapi

npm install --save bs-webapi
Enter fullscreen mode Exit fullscreen mode

Add the entry to bsconfig.json

"bs-dependencies": ["bs-webapi"],
Enter fullscreen mode Exit fullscreen mode

use the following snippet

open Webapi.Dom
open Belt

document
->Document.asHtmlDocument
->Option.flatMap(document => document->HtmlDocument.body)
->Option.map(body => {
  let root = document->Document.createElement("div", _)
  root->Element.setId("app")
  // ReactDOM.render(<App />, root) // if you are using react
  root->Element.appendChild(body)
})
->ignore
Enter fullscreen mode Exit fullscreen mode

Top comments (0)