redraw/dom/client

Types

Root to display React DOM.
Documentation

pub type Root

Functions

pub fn create_root(root: String) -> Result(Root, Nil)

Let you create a root to display React components inside a browser DOM node. Contrarily to JavaScript, create_root returns a Result to avoid runtime error. Indeed, when the provided root does not exist in your HTML, create_root fails. You should never assume create_root will work out-of-the-box when you’re building a library. Otherwise, you could assert the resulting value in your application.

import redraw/dom/client

pub fn main() {
  let assert Ok(root) = client.create_root("app")
  client.render(root, app())
}

Documentation

pub fn hydrate_root(
  root: String,
  node: Component,
) -> Result(Root, Nil)

Let you display React components inside a browser DOM node whose HTML content was previously generated by react-dom/server. Contrarily to JavaScript, hydrate_root returns a Result to avoid runtime error. Indeed, when the provided root does not exist in your HTML, hydrate_root fails. You should never assume hydrate_root will work out-of-the-box when you’re building a library. Otherwise, you could assert the resulting value in your application.

import redraw/dom/client

pub fn main() {
  let assert Ok(root) = client.hydrate_root("app")
}

Documentation

pub fn render(root: Root, child: Component) -> Nil

Call render(root) to display a piece of JSX (“React node”) into the React root’s browser DOM node.
Documentation

Search Document