DEV Community

Arbaaz
Arbaaz

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

1 2

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)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More