Notice the type="module" attribute on the script tag. If all module dependencies are ES Module (ESM) compliant, and they are all available from within the browser, you don't need a module bundler to get started (assuming you're using a browser that supports ES modules).
InGreeting.re, add the following greeting function:
let div = createElement("div"); setInnerText(div, Greeting.greeting("world")); appendChild(div);
Using BuckleScript's powerful interoperability features (which we will dive into in Chapter 4, BuckleScript, Belt and Interoperability) the preceding code binds to existing browser APIs, namelydocument.createElement,innerText, anddocument.body.appendChild, and then uses those bindings to create adivwith some text that is appended to the body of the document.
Runnpm run build, start a server (perhaps withphp -S localhost:3000 in a new console tab) at the root of the project, and then navigate tohttp://localhost:3000 to see our newly-created DOM element:
The takeaway is that having to work with the DOM in this way is really tedious. It's hard to type DOM APIs due to JavaScript's dynamic nature. For example, Element.innerTextis used both to get and set an element'sinnerText, depending on how it's used, which therefore would result in two different type signatures:
Luckily, we have React, which largely abstracts the DOM for us. Using React, we don't need to worry about typing the DOM APIs. It's nice to know that when we want to interact with various browser APIs, BuckleScript has the tools we need to get the job done. While it's certainly possible to write frontend web applications in pure Reason, it's a much more pleasant experience when using ReasonReact, especially when first getting started with Reason.