Sign in

    react

    Type-safe MoonBit bindings for React with virtual DOM, hooks, and CSS-in-JS support (early experimental)

    react
    binding
    Download zip
    Author
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    last month
    Downloads
    293

    #tiye/react

    React bindings for MoonBit

    #Project Status

    🚧 This is an early project

    This is an experimental hobby project exploring MoonBit bindings for React. The API is unstable and may change frequently. Not recommended for production use. This project is intended for technical exploration and learning purposes only.

    #API Stability and JavaScript Boundary

    All public APIs are experimental. The virtual-node, element-helper, and basic hook APIs are the maintained baseline; React 19 concurrent hooks and the broad event catalogue are newer additions that should receive application-level testing before adoption. Deprecated compatibility APIs remain available only until the next breaking release.

    JsObscure is the explicit escape hatch at the MoonBit/JavaScript boundary. Use it for hook dependency values with obscure(value) and for intentional JS interoperation only. Generic hook and component values cross React using the MoonBit JavaScript representation, so they must be values that the generated MoonBit runtime can pass directly; do not assume JSON serialization or deep cloning occurs.

    The browser entry point must initialize globalThis.React, globalThis.ReactDOM, and globalThis.ReactDOMClient before calling this package. (window and globalThis are the same global object in a browser.) ReactDOM supplies DOM-specific Hooks such as use_form_status; the bundled demo shows the supported ESM integration pattern.

    Component functions must be placed in the virtual DOM through component, not called directly. Use component_with_children when the component needs to place caller-supplied children in its own tree.

    Apply with_key to children in dynamic collections, using stable application identities rather than array indexes.

    #Bound APIs and Types

    #Core Rendering API

    • render(vdom: VirtualNode, parent: @dom.Element) -> Unit - Render virtual DOM to specified parent element
    • render_with_options(vdom: VirtualNode, parent: @dom.Element, options: RootOptions) -> Unit - Create and render through a configured React root
    • hydrate_root(vdom: VirtualNode, parent: @dom.Element, options?: RootOptions) -> Unit - Attach React to matching server-rendered HTML
    • unmount(parent: @dom.Element) -> Unit - Unmount the React root for an element
    • create_portal(child: VirtualNode, parent: @dom.Element, key?: String) -> VirtualNode - Place DOM in another container while retaining React-tree context and event propagation
    • render_to_string(vdom: VirtualNode, identifier_prefix?: String) -> String - Basic synchronous SSR/SSG renderer
    • RootOptions::new(...) -> RootOptions - Configure identifierPrefix and caught, uncaught, and recoverable error callbacks
    • ReactError::message() -> String, ReactErrorInfo::component_stack() -> String - Inspect root callback values
    • component[T](f: (T) -> VirtualNode, props: T, children: Array[VirtualNode]) -> VirtualNode - Create a leaf component
    • component_with_children[T](f: (T, Array[VirtualNode]) -> VirtualNode, props: T, children: Array[VirtualNode]) -> VirtualNode - Create a component that places its children
    • define_component[T](render: (T) -> VirtualNode) -> ReactComponent[T] - Define a stable reusable component type with typed MoonBit props
    • ReactComponent::render(props: T) -> VirtualNode - Render a reusable typed component
    • ReactComponent::memo(are_props_equal?: (T, T) -> Bool) -> ReactComponent[T] - Memoize a typed component with default identity or a typed comparator
    • lazy_component[T](loader: async () -> ReactComponent[T]) -> ReactComponent[T] - Lazily load and cache a typed component through Suspense
    • suspense(fallback: VirtualNode, children: Array[VirtualNode]) -> VirtualNode - Display fallback UI until suspended children are ready
    • component_from_js[T](component: JsObscure) -> ReactComponent[T] - Declare the typed MoonBit props contract for a trusted JavaScript component
    • VirtualNode::with_key(key: String) -> VirtualNode - Assign a stable React reconciliation key without adding a DOM wrapper
    • create_context[T](default_value: T) -> ReactContext[T] - Create a typed React Context
    • ReactContext::provider(value: T, children: Array[VirtualNode]) -> VirtualNode - Provide a value without adding a DOM wrapper

    For example, use component(my_component, props, []), never my_component(props) directly in a virtual DOM tree.

    #Hooks API

    • use_state[T](initial: T) -> (T, (T) -> Unit) - State management hook
    • use_context[T](context: ReactContext[T]) -> T - Read and subscribe to the nearest typed Context provider
    • use_state_with_updater[T](initial: T) -> (T, (StateUpdate[T]) -> Unit) - State hook with direct and functional updates
    • use_reducer_with_initial[S, A](initial: S, reducer: (S, A) -> S) -> (S, (A) -> Unit) - Reducer hook for any explicit state type
    • use_reducer[S: Default, A](initial?: S, reducer: (S, A) -> S) -> (S, (A) -> Unit) - Reducer hook
    • use_effect_once(effect: () -> Unit) -> Unit - Effect hook that runs only once
    • use_effect_cleanup_deps(effect: () -> () -> Unit, deps: Array[JsObscure]) -> Unit - Effect hook with a cleanup function
    • use_effect_once_with_cleanup(effect: () -> () -> Unit) -> Unit - One-time effect with a cleanup function
    • use_effect_deps(effect: () -> Unit, deps: Array[JsObscure]) -> Unit - Effect hook with dependencies
    • use_layout_effect_deps(effect: () -> Unit, deps: Array[JsObscure]) -> Unit - Layout effect hook
    • use_memo_deps[A](factory: () -> A, deps: Array[JsObscure]) -> A - Memoization hook
    • use_callback_deps[F](callback: F, deps: Array[JsObscure]) -> F - Callback memoization hook
    • use_effect_event[F](callback: F) -> F - React 19.2 effect-only callback that reads latest state without re-subscribing an effect
    • use_action_state[S, A](initial: S, action: (S, A) -> S) -> (S, (A) -> Unit, Bool) - React 19 action state, dispatch, and pending flag
    • use_async_action_state[S, A](initial: S, action: async (S, A) -> S) -> (S, (A) -> Unit, Bool) - Export a MoonBit async reducer as a Promise-returning React Action
    • use_optimistic[S, A](value: S, reducer: (S, A) -> S) -> (S, (A) -> Unit) - Temporary optimistic state scoped to a React Action
    • use_form_status() -> FormStatus - Read pending data, method, and action from the nearest parent form
    • use_callback0_deps(f: () -> Unit, deps: Array[JsObscure]) -> () -> Unit - Zero-argument callback hook
    • use_ref[T](initial: T) -> ReactRef[T] - Reference hook
    • use_dom_ref() -> ReactDomRef - Nullable DOM-element ref hook whose current() value is None before mount and after unmount
    • use_id() -> String - Stable component-local identifier hook
    • use_deferred_value[T](value: T) -> T - Deferred-value hook for non-urgent rendering
    • use_transition() -> (Bool, (() -> Unit) -> Unit) - Transition state and starter hook
    • start_transition(action: () -> Unit) -> Unit - Start a transition when pending state is not needed
    • use_sync_external_store[T](subscribe, get_snapshot, get_server_snapshot?) -> T - Read and subscribe to a typed immutable external-store snapshot
    • use_imperative_ref[T]() -> ImperativeRef[T] - Create a nullable typed ref for a custom component handle
    • use_imperative_handle_deps[T](ref: ImperativeRef[T], create_handle: () -> T, deps: Array[JsObscure]) -> Unit - Expose a typed React 19 imperative handle
    • obscure[T](v: T) -> JsObscure - Dependency conversion helper function

    #HTML Element Bindings

    • div, span, p, h1, h2, h3 - Basic text elements
    • form, button, input, textarea, select, option - Form elements
    • a, img, video, audio - Media and link elements
    • ul, ol, li - List elements
    • section, article, header, footer, nav, aside - Semantic elements
    • label - Label element
    • Generated table helpers: table, caption, colgroup, col, thead, tbody, tfoot, tr, th, and td
    • Generated form and interactive helpers: fieldset, legend, datalist, optgroup, output, progress, meter, dialog, details, and summary
    • Generated React 19 metadata helpers: title, meta, link, style_tag, and script_tag
    • Generated core SVG helpers include svg, g, defs, symbol, path, circle, ellipse, rect, line, gradients, clipping/masking, text, and use_

    The generated set contains 54 helpers across six categories. Every generated helper includes typed common role, title, tab_index, hidden, aria_label, and data_testid props plus the applicable tag-specific props. SVG and metadata names use React camel case at the JavaScript boundary, such as viewBox, strokeWidth, httpEquiv, and xlinkHref.

    #Event Handling

    DOMEventType covers clipboard, composition, keyboard, mouse, pointer, wheel, form, drag, touch, media, animation, and transition events. It maps each value to React's camel-cased onXxx property automatically.

    • DOMEvent type and its methods:
      • target_value() -> String - Get form element value
      • target_checked() -> Bool - Get checkbox or radio checked state
      • key() -> String, key_code() -> Int - Keyboard events
      • client_x() -> Int, client_y() -> Int - Mouse coordinates
      • prevent_default(), stop_propagation() - Event control
      • ctrl_key(), shift_key(), alt_key(), meta_key() -> Bool - Modifier key detection

    #Styles and Attributes

    • ElementAttrs - HTML attribute management, including typed string, boolean, integer, floating-point, and JavaScript-value setters
    • ElementEvents - Event handler management
    • RespoStyle - CSS styles (from @css module)
    • InputType enum - Support for all HTML input types
    • StateUpdate[T] - Set(value) or Update(fn(previous) { ... }) for safely deriving state from the latest React value

    innerHTML parameters are converted to React's dangerouslySetInnerHTML API. Only pass trusted, sanitized HTML through this escape hatch. Combining innerHTML with children is rejected before the element reaches React.

    Use ElementAttrs::set for string attributes, set_bool for React boolean properties such as disabled, set_int for integral properties such as rows, and set_float for fractional numeric properties such as progress and meter values. The built-in element helpers use these typed conversions automatically. Use set_js_value only for explicit React values such as a DOM ref: attrs.set_js_value("ref", input_ref.to_js_obscure()). For controlled checkbox or radio inputs, use input(checked=value) so both true and false reach React as booleans. Use default_value and default_checked for uncontrolled form elements; combining them with value or checked is rejected. For DOM elements, prefer use_dom_ref() and attach its JavaScript ref object through set_js_value. ReactDomRef::current() returns Some(element) only while the element is mounted. Controlled fields require on_change, or an explicit read_only=true or disabled=true state. A multiple=true select uses the values or default_values array parameters; individual options do not accept selected.

    React 19 function Actions use the typed FormAction wrapper. Wrap the ReactFormData dispatcher returned by use_action_state or use_async_action_state with form_action(dispatch), or convert a direct MoonBit async form function with async_form_action. Pass the result through form(action=...), button(form_action=...), or a submit/image input(form_action=...). use_form_status must run in a child component below the form it observes. The async bridge is pinned to moonbitlang/async@0.20.3, the newest release compatible with this repository's pinned MoonBit compiler.

    declare_contained_style is deprecated; use contained_static_style instead. ReactRef::from is deprecated because its constructor-like name hides a Hook call; use use_ref or use_dom_ref at the top level of a component.

    Static-style declarations are safe during server-side rendering or pre-rendering: without a browser document they return their deterministic class name without injecting a tag. The browser's module evaluation then performs the injection.

    #Portals, Roots, and SSR Scope

    create_portal changes physical DOM placement only: context and events still follow the owning React tree. render_with_options applies its options only when it creates a root; later calls for the same parent reuse that root.

    The supported SSR/SSG path is deliberately narrow and explicit:

    • render_to_string is a synchronous react-dom/server binding.
    • hydrate_root requires markup identical to the initial client tree.
    • identifier_prefix must be identical in render_to_string and RootOptions::new when the tree uses use_id.
    • Streaming, waiting for suspended data, async server rendering, React Server Components, and framework routing/data protocols are not provided.

    For a server or build entry, initialize only the renderer globals it needs:

    import * as React from "react"; import * as ReactDOMServer from "react-dom/server"; globalThis.React = React; globalThis.ReactDOMServer = ReactDOMServer;

    Then initialize React, ReactDOM, and ReactDOMClient in the browser entry before calling hydrate_root. Do not bundle react-dom/server into ordinary client code merely to hydrate markup that was already generated on the server.

    #External Stores and Component Integration

    use_sync_external_store follows React's immutable snapshot contract. Keep the subscribe function stable across renders, return an unsubscribe callback, and return the same snapshot value while the store has not changed. When rendering on the server, provide get_server_snapshot and return the same initial value during hydration.

    ReactComponent[T] carries a single typed MoonBit props value. A component created through component_from_js receives that value as props.moonbitProps; this explicit carrier avoids spreading or depending on MoonBit's generated JavaScript object representation. memo compares this single value with Object.is by default, or receives previous and next typed values in its custom comparator.

    Declare memoized and lazy components outside ordinary render paths. A lazy_component loader resolves to ReactComponent[T]; React caches both the loader Promise and its resolved component. Render it below suspense so a fallback is visible while loading.

    React 19 makes refs available as component props, so this binding intentionally does not add a new forwardRef wrapper. Pass ImperativeRef[T] through typed props and call use_imperative_handle_deps in the child. current() returns None before commit and after cleanup. Prefer declarative props whenever the behavior does not genuinely require an imperative handle.

    #Virtual DOM Types

    • VirtualNode - Base virtual node type
    • VirtualElement - Virtual element type
    • Text(String) - Text node

    #Quick Start

    Before writing any MoonBit code, make sure to include the React bindings in your project.

    import * as React from "react"; import * as ReactDOM from "react-dom"; import * as ReactDOMClient from "react-dom/client"; globalThis.React = React; globalThis.ReactDOM = ReactDOM; globalThis.ReactDOMClient = ReactDOMClient;

    Here's a simple example of how to use this library:

    // Define your component props
    struct ContainerProps {} derive(Default)

    // Create a functional component
    fn comp_container(_v : ContainerProps) -> @react.VirtualNode {
    let (counter, set_counter) = @react.use_state(Float::from_double(0.0))

    @react.div(
    id="container",
    style=@css.respo_style(
    color=@css.CssColor::Blue,
    font_family="Arial",
    padding=@css.CssSize::Px(10.0),
    ),
    on_click=fn(_) {
    println("clicked \{counter}")
    set_counter(counter + 1.0)
    },
    [
    @react.Fragment([@react.Text("Demo: ")]),
    @react.Text("Counter \{counter}")
    ],
    )
    }

    // Render to DOM
    fn main {
    let window = @dom.window()
    let doc = window.document()
    let body = doc.body()
    let props : ContainerProps = Default::default()

    @react.render(
    @react.component(comp_container, props, []),
    body,
    )
    println("loaded")
    }

    #Features

    • Type-safe virtual DOM construction
    • React-style hooks (useState)
    • CSS-in-JS styling support
    • Event handling
    • Component composition

    #Development

    The package follows the current MoonBit manifest format (moon.mod and moon.pkg). To run the checks locally:

    moon check moon test moon info corepack yarn install --frozen-lockfile corepack yarn generate:dom corepack yarn check:generated corepack yarn build corepack yarn test:browser

    CI pins MoonBit compiler 0.10.4+2cc641edf and validates Node 22 with Yarn 1.22.22. test:browser runs deterministic TodoMVC and React runtime conformance flows in Chromium, including StrictMode lifecycle, batching, root reuse, DOM ref cleanup, async form Actions, form status, optimistic rollback, portals, root error callbacks, synchronous server rendering, hydration, external-store subscription lifecycles, memo/lazy/Suspense, typed JavaScript interoperation, imperative handles, and generated HTML/SVG/metadata DOM behavior; install it once locally with yarn playwright install chromium. Update the toolchain pin only through the full check, unit-test, interface, browser-test, and browser-build matrix. This revision was verified with MoonBit 0.1.20260713, React 19.2.8, and Vite 8.2.x.

    The browser entry point loads React, ReactDOM, ReactDOMClient, and the demo-only server renderer before the generated MoonBit application. render can be called again for the same parent element; the binding reuses its React root rather than creating a second one.

    #Release

    Prepare releases on a branch by aligning moon.mod, package.json, the dated Changelog section, and bilingual release-notes/vX.Y.Z.md. Run yarn check:release; it requires exact version agreement, complete historical tag coverage, an empty Unreleased section, and an exact 17-file package allowlist.

    After the preparation PR is merged, create and push an annotated vX.Y.Z tag that points to main. The release workflow verifies tag identity and main ancestry, generated sources, MoonBit check/test/interface/format results, real Chromium conformance, the browser build, and the package allowlist. It creates a GitHub Release whose title exactly matches the tag and attaches both the MoonBit archive and SHA256SUMS.

    Publishing to mooncakes.io remains a separate authenticated step because the registry credential is deliberately not stored in GitHub Actions. Log in with moon login, run moon publish --frozen, then prove the exact published version from a fresh temporary consumer:

    corepack yarn verify:published X.Y.Z

    The same check is available through the manual Verify published package workflow. It resolves tiye/react@X.Y.Z, compiles a generated-DOM smoke use, and preserves the command metrics as a workflow artifact. A release is not complete until this downstream check passes.

    #License

    Apache 2.0

    DOMEvent

    pub type DOMEvent

    DOMEvent::alt_key

    fn DOMEvent::alt_key(self : DOMEvent) -> Bool

    检查是否按下了 Alt 键

    DOMEvent::client_x

    fn DOMEvent::client_x(self : DOMEvent) -> Int

    获取鼠标事件的 X 坐标

    DOMEvent::client_y

    fn DOMEvent::client_y(self : DOMEvent) -> Int

    获取鼠标事件的 Y 坐标

    DOMEvent::ctrl_key

    fn DOMEvent::ctrl_key(self : DOMEvent) -> Bool

    检查是否按下了 Ctrl 键

    DOMEvent::key

    fn DOMEvent::key(self : DOMEvent) -> String

    获取键盘事件的键值

    DOMEvent::key_code

    fn DOMEvent::key_code(self : DOMEvent) -> Int

    获取键盘事件的键码

    DOMEvent::meta_key

    fn DOMEvent::meta_key(self : DOMEvent) -> Bool

    检查是否按下了 Meta 键(Mac 上的 Cmd 键)

    DOMEvent::prevent_default

    fn DOMEvent::prevent_default(self : DOMEvent) -> Unit

    阻止事件的默认行为

    DOMEvent::shift_key

    fn DOMEvent::shift_key(self : DOMEvent) -> Bool

    检查是否按下了 Shift 键

    DOMEvent::stop_propagation

    fn DOMEvent::stop_propagation(self : DOMEvent) -> Unit

    阻止事件冒泡

    DOMEvent::target_checked

    fn DOMEvent::target_checked(self : DOMEvent) -> Bool

    Returns whether the event target is checked. This is intended for controlled checkbox and radio inputs; non-checkable targets return false.

    DOMEvent::target_value

    fn DOMEvent::target_value(self : DOMEvent) -> String

    获取事件目标元素的值(通常用于 input、textarea 等表单元素)

    DOMEvent::to_js_obscure

    DOMEventType

    pub(all) enum DOMEventType {
    Copy
    Cut
    Paste
    CompositionEnd
    CompositionStart
    CompositionUpdate
    Click
    DoubleClick
    MouseDown
    MouseUp
    MouseMove
    MouseEnter
    MouseLeave
    MouseOver
    MouseOut
    ContextMenu
    PointerDown
    PointerMove
    PointerUp
    PointerCancel
    PointerEnter
    PointerLeave
    PointerOver
    PointerOut
    GotPointerCapture
    LostPointerCapture
    KeyDown
    KeyUp
    KeyPress
    BeforeInput
    Input
    Change
    Submit
    Reset
    Focus
    Blur
    Select
    Load
    Unload
    Resize
    Scroll
    Wheel
    Drag
    DragStart
    DragEnd
    DragEnter
    DragLeave
    DragOver
    Drop
    TouchStart
    TouchMove
    TouchEnd
    TouchCancel
    Error
    Abort
    CanPlay
    CanPlayThrough
    DurationChange
    Ended
    LoadedData
    LoadedMetadata
    LoadStart
    Pause
    Play
    Playing
    Progress
    RateChange
    Seeked
    Seeking
    Stalled
    Suspend
    TimeUpdate
    VolumeChange
    Waiting
    AnimationStart
    AnimationEnd
    AnimationIteration
    TransitionEnd
    Invalid
    Toggle
    Cancel
    Close
    } derive(Compare, Eq, Hash)

    DOM 事件类型枚举

    DOMEventType::to_string

    fn DOMEventType::to_string(self : DOMEventType) -> String

    将 DOMEventType 转换为字符串

    ElementAttrs

    pub struct ElementAttrs(Map[String, ElementPropValue]) derive(Default)

    ElementAttrs::add

    fn ElementAttrs::add(self : ElementAttrs, key : String, value : String) -> ElementAttrs

    Adds a string-valued React property and returns the same attribute map.

    ElementAttrs::new

    ElementAttrs::set

    fn ElementAttrs::set(self : ElementAttrs, key : String, value : String) -> Unit

    Sets a string-valued React property.

    ElementAttrs::set_bool

    fn ElementAttrs::set_bool(self : ElementAttrs, key : String, value : Bool) -> Unit

    Sets a boolean React property without converting it to a string.

    ElementAttrs::set_float

    fn ElementAttrs::set_float(self : ElementAttrs, key : String, value : Float) -> Unit

    Sets a floating-point React property without converting it to a string.

    ElementAttrs::set_int

    fn ElementAttrs::set_int(self : ElementAttrs, key : String, value : Int) -> Unit

    Sets an integer React property without converting it to a string.

    ElementAttrs::set_js_value

    fn ElementAttrs::set_js_value(self : ElementAttrs, key : String, value :
    JsObscure
    ) -> Unit

    Sets an explicitly pre-converted JavaScript property. Use this escape hatch for React values such as ref that cannot be represented as strings, booleans, or integers.

    ElementEvents

    type ElementEvents derive(Default)

    ElementEvents::add

    fn ElementEvents::add(self : ElementEvents, event_type : DOMEventType, value : (DOMEvent) -> Unit) -> ElementEvents

    使用 DOMEventType 添加事件处理器

    ElementEvents::new

    ElementEvents::set

    fn ElementEvents::set(self : ElementEvents, event_type : DOMEventType, value : (DOMEvent) -> Unit) -> Unit

    使用 DOMEventType 设置事件处理器

    ElementEvents::to_js_value

    ElementPropValue

    type ElementPropValue

    FormAction

    type FormAction

    A typed React action or formAction property.

    FormStatus

    type FormStatus

    Status for the nearest parent React form. A component calling this Hook must be rendered below the form rather than in the same component that creates it.

    FormStatus::action

    fn FormStatus::action(self : FormStatus) -> FormAction?

    FormStatus::data

    fn FormStatus::data(self : FormStatus) -> ReactFormData?

    Returns the submitted data while the parent form Action is pending.

    FormStatus::pending

    fn FormStatus::pending(self : FormStatus) -> Bool

    FormStatus::submission_method

    fn FormStatus::submission_method(self : FormStatus) -> String

    ImperativeRef

    type ImperativeRef[T]

    A nullable typed ref for a custom imperative component handle.

    ImperativeRef::current

    fn[T] ImperativeRef::current(self : ImperativeRef[T]) -> T?

    Returns the committed handle, or None before mount and after cleanup.

    ImperativeRef::to_js_obscure

    Returns the underlying React ref object for an explicit JavaScript bridge.

    InputType

    pub(all) enum InputType {
    Button
    Checkbox
    Color
    Date
    DatetimeLocal
    Email
    File
    Hidden
    Image
    Month
    Number
    Password
    Radio
    Range
    Reset
    Search
    Submit
    Tel
    Text
    Time
    Url
    Week
    } derive(Eq)

    HTML input element type enumeration based on MDN specification https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input

    InputType::to_string

    fn InputType::to_string(self : InputType) -> String

    Converts InputType enum to its corresponding HTML string value

    ReactComponent

    type ReactComponent[T]

    A stable React component type carrying one typed MoonBit props value.

    Render it with ReactComponent::render. JavaScript component bridges receive the typed value in a single moonbitProps property rather than relying on the generated representation being spread into JavaScript props.

    ReactComponent::memo

    fn[T] ReactComponent::memo(self : ReactComponent[T], are_props_equal? : (T, T) -> Bool) -> ReactComponent[T]

    Returns a memoized component. Without are_props_equal, React compares the single typed moonbitProps value with Object.is; a custom comparator receives the previous and next MoonBit values directly.

    ReactComponent::render

    fn[T] ReactComponent::render(self : ReactComponent[T], props : T) -> VirtualNode

    Renders this component with one typed MoonBit props value.

    ReactComponent::to_js_obscure

    Returns the underlying React component type for explicit JavaScript interoperation.

    ReactContext

    type ReactContext[T]

    A typed handle to a React Context object.

    ReactContext::provider

    fn[T] ReactContext::provider(self : ReactContext[T], value : T, children : Array[VirtualNode]) -> VirtualNode

    Provides value to descendant components without adding a DOM wrapper.

    ReactContext::to_js_obscure

    Returns the underlying Context object for explicit JavaScript interoperation.

    ReactDomRef

    type ReactDomRef

    A DOM element ref whose current value is absent before mount and after unmount. Attach it with ElementAttrs::set_js_value("ref", ref.to_js_obscure()).

    ReactDomRef::current

    Returns the mounted DOM element, or None before mount and after unmount.

    ReactDomRef::to_js_obscure

    Returns the underlying React ref object for an explicit ref prop.

    ReactError

    #external
    pub type ReactError

    The JavaScript error passed to a React root error callback.

    ReactError::message

    fn ReactError::message(self : ReactError) -> String

    Returns the JavaScript Error message reported by React.

    ReactErrorInfo

    #external
    pub type ReactErrorInfo

    Metadata passed to a React root error callback.

    ReactErrorInfo::component_stack

    fn ReactErrorInfo::component_stack(self : ReactErrorInfo) -> String

    Returns the React component stack associated with a root error.

    ReactFormData

    #external
    pub type ReactFormData

    The browser FormData payload supplied to React form Actions.

    ReactFormData::get_string

    fn ReactFormData::get_string(self : ReactFormData, key : String) -> String?

    Returns a string form field, or None when the field is absent or is a non-string value such as a File.

    ReactRef

    type ReactRef[T]

    ReactRef::from

    #deprecated("This function is deprecated.")
    fn[T] ReactRef::from(initial : T) -> ReactRef[T]

    Deprecated Hook-shaped constructor for ReactRef.

    Despite its constructor-like name, this calls React useRef and therefore must only run at the top level of a component or another Hook. Use use_ref(initial) instead, or use_dom_ref() for nullable DOM refs.

    ReactRef::get

    fn[T] ReactRef::get(self : ReactRef[T]) -> T

    ReactRef::set

    fn[T] ReactRef::set(self : ReactRef[T], value : T) -> Unit

    ReactRef::to_js_obscure

    fn[T] ReactRef::to_js_obscure(self : ReactRef[T]) ->
    JsObscure

    Returns the underlying React ref object for an explicit JavaScript property, for example attrs.set_js_value("ref", input_ref.to_js_obscure()).

    RootOptions

    type RootOptions

    Configuration shared by createRoot and hydrateRoot.

    RootOptions::new

    fn RootOptions::new(identifier_prefix? : String, on_caught_error? : (ReactError, ReactErrorInfo) -> Unit, on_uncaught_error? : (ReactError, ReactErrorInfo) -> Unit, on_recoverable_error? : (ReactError, ReactErrorInfo) -> Unit) -> RootOptions

    Creates root options matching React 19's root error and identifier options. identifier_prefix must match the server renderer during hydration.

    StateUpdate

    pub(all) enum StateUpdate[T] {
    Set(T)
    Update((T) -> T)
    }

    Represents a React state update. Set replaces state directly and Update calculates the next state from React's current value.

    VirtualElement

    pub struct VirtualElement {
    name : String
    attrs : ElementAttrs
    event : ElementEvents
    style :
    RespoStyle

    children : Array[VirtualNode]
    }

    Represents a virtual DOM element with all its properties and children.

    This structure encapsulates all the information needed to create and manage a DOM element in the virtual DOM tree, including its tag name, attributes, event handlers, styles, and child nodes.

    VirtualElement::to_node

    VirtualNode

    pub(all) enum VirtualNode {
    Element(VirtualElement)
    Fragment(Array[VirtualNode])
    Text(String)
    JsNode(
    JsObscure
    )
    }

    Represents a virtual DOM node in the React rendering system.

    This is the core type for building virtual DOM trees. Each variant represents a different kind of node that can be rendered to the actual DOM.

    VirtualNode::to_js_obscure

    VirtualNode::with_key

    fn VirtualNode::with_key(self : VirtualNode, key : String) -> VirtualNode

    Assigns a stable React reconciliation key to a virtual node.

    This works uniformly for elements, components, fragments, and text without adding a DOM wrapper. Use stable application identities rather than list indexes when rendering dynamic collections.
    fn a(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, href? : String, target? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an a element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing an a element.

    address

    fn address(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the address semantic element.

    article

    fn article(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an article element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing an article element.

    aside

    fn aside(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an aside element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing an aside element.

    async_form_action

    fn async_form_action(action : async (ReactFormData) -> Unit) -> FormAction

    Converts a MoonBit async form Action into a JavaScript Promise-returning React Action. Rejections are forwarded to React by the official moonbitlang/async/js_async bridge.

    audio

    fn audio(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], src? : String, controls? : Bool, autoplay? : Bool, loop_enabled? : Bool, muted? : Bool, on_play? : (DOMEvent) -> Unit, on_pause? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an audio element with the specified attributes, event handlers, and audio properties.

    Returns a virtual DOM node representing an audio element.

    blockquote

    fn blockquote(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, cite? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the blockquote semantic element.

    button

    fn button(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, button_type? : String, name? : String, value? : String, disabled? : Bool, form_action? : FormAction, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a button element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing a button element.

    caption

    fn caption(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the caption table element.

    circle

    fn circle(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, cx? : String, cy? : String, r? : String, fill? : String, stroke? : String, stroke_width? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the circle svg element.

    clip_path

    fn clip_path(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the clipPath svg element.

    code

    fn code(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the code semantic element.

    col

    fn col(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, span? : Int, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the col table element.

    colgroup

    fn colgroup(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, span? : Int, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the colgroup table element.

    component

    fn[T] component(f : (T) -> VirtualNode, props : T, children : Array[VirtualNode]) -> VirtualNode

    Creates a component virtual node from a function, props, and children.

    This bridges MoonBit component functions with React's rendering system, enabling type-safe component creation with strongly-typed props.

    Example

    struct ButtonProps {
    text : String
    disabled : Bool
    } derive(Default)

    fn my_button(props : ButtonProps) -> VirtualNode {
    button(disabled=props.disabled, [Text(props.text)])
    }

    let node = component(my_button, ButtonProps { text: "Click me", disabled: false }, [])

    component_from_js

    fn[T] component_from_js(component :
    JsObscure
    ) -> ReactComponent[T]

    Declares the expected MoonBit props type for a trusted JavaScript React component. The JavaScript component receives { moonbitProps } and the rendered value remains a JsNode escape hatch.

    component_with_children

    fn[T] component_with_children(f : (T, Array[VirtualNode]) -> VirtualNode, props : T, children : Array[VirtualNode]) -> VirtualNode

    Creates a component virtual node whose function receives the child nodes.

    Use this when a component needs to decide where to place its children. The existing component function remains the concise choice for leaf components.

    console_log2

    fn console_log2(msg : String, v :
    JsObscure
    ) -> Unit

    contained_static_style

    #callsite(autofill(loc))
    fn[U : Show] contained_static_style(rules : Array[(String?, U,
    RespoStyle
    )], loc~ : SourceLoc) -> String

    Declares a static style in the document head, for example:
    let style_demo : String = contained_static_style(
    [(Some("@media only screen and (max-width: 600px)"), "&", respo_style(margin=4 |> Px, background_color=Hsl(200, 90, 96)))],
    )

    convert_prop_value

    fn convert_prop_value(prop_name : String, value : String) ->
    JsObscure

    Converts string values to appropriate JavaScript values for React props. Handles boolean attributes by converting "true"/"false" strings to actual booleans. The internal innerHTML attribute is converted to React's dangerouslySetInnerHTML object; only provide trusted HTML to that API.

    Parameters

    • prop_name: React property name.
    • value: String value from the attribute.

    Returns

    JsObscure - Properly typed JavaScript value for React.

    Inspect Examples

    inspect(convert_prop_value("checked", "true"), content="JsObscure::from_bool(true)") inspect(convert_prop_value("className", "my-class"), content="JsObscure::from_string("my-class")")

    convert_style_to_js_object

    create_context

    fn[T] create_context(default_value : T) -> ReactContext[T]

    Creates a typed React Context with the value returned when no matching provider exists above a consumer.

    Create contexts outside ordinary render paths, or memoize them when their lifetime intentionally belongs to a component instance.

    create_element

    fn create_element(name : String, attrs : ElementAttrs, event : ElementEvents, style~ :
    RespoStyle
    , children : Array[VirtualNode]) -> VirtualElement

    Creates a virtual DOM element with the specified properties.

    This is the internal implementation used by built-in element functions like div, span, etc. It can also be used to create custom HTML elements that are not provided by the library.

    Parameters

    • name: HTML tag name (e.g., "div", "span", "custom-element")
    • attrs: Element attributes
    • event: Event handlers
    • style: CSS styles
    • children: Child virtual nodes

    Example

    // Create a custom element
    let _custom_elem = create_element(
    "my-custom-element",
    ElementAttrs::new(),
    ElementEvents::new(),
    style=@css.respo_style(),
    [Text("Custom content")],
    )

    create_portal

    fn create_portal(child : VirtualNode, parent :
    Element
    , key? : String) -> VirtualNode

    Creates a React portal whose DOM is placed in parent while context and event propagation continue to follow the owning React tree.

    css_prop_to_camel_case

    fn css_prop_to_camel_case(name : String) -> String

    Converts CSS property names from hyphen-case (kebab-case) to React camelCase. Supports vendor prefixes (leading hyphen) by capitalizing the first segment.

    Parameters

    • name: CSS property name such as "background-color" or "-webkit-line-clamp".

    Returns

    String - React-style camelCase property.

    inspect(css_prop_to_camel_case("background-color"), content="backgroundColor") inspect(css_prop_to_camel_case("border-top-left-radius"), content="borderTopLeftRadius") inspect(css_prop_to_camel_case("-webkit-line-clamp"), content="WebkitLineClamp")

    datalist

    fn datalist(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the datalist form element.

    declare_contained_style

    #deprecated("This function is deprecated.")
    #callsite(autofill(loc))
    fn[U : Show] declare_contained_style(rules : Array[(String?, U,
    RespoStyle
    )], loc~ : SourceLoc) -> String

    Deprecated compatibility alias for contained_static_style.

    Use contained_static_style in new code. This alias remains available for existing callers and will be removed only in a future breaking release.

    define_component

    fn[T] define_component(render_component : (T) -> VirtualNode) -> ReactComponent[T]

    Defines a stable typed React component from a MoonBit render function. Prefer module-level declarations; repeated calls with the same function also reuse the same JavaScript component type.

    defs

    fn defs(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the defs svg element.

    details

    fn details(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, open? : Bool, on_click? : (DOMEvent) -> Unit, on_toggle? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the details interactive element.

    dialog

    fn dialog(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, open? : Bool, on_click? : (DOMEvent) -> Unit, on_cancel? : (DOMEvent) -> Unit, on_close? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the dialog interactive element.

    div

    fn div(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    dom_attr_to_react_prop

    fn dom_attr_to_react_prop(attr_name : String) -> String

    Converts legacy DOM attribute names to React-compatible property names. This function provides backward compatibility for traditional HTML attribute names. Most attributes should use the correct React property names directly in element definitions.

    Parameters

    • attr_name: HTML attribute name such as "class", "for", or "innerHTML".

    Returns

    String - React-compatible property name.

    inspect(dom_attr_to_react_prop("class"), content="className") inspect(dom_attr_to_react_prop("for"), content="htmlFor") inspect(dom_attr_to_react_prop("innerHTML"), content="dangerouslySetInnerHTML") inspect(dom_attr_to_react_prop("id"), content="id") inspect(dom_attr_to_react_prop("data-test"), content="data-test")

    dom_event_to_react_handler

    fn dom_event_to_react_handler(event_type : DOMEventType) -> String

    Converts DOM event types to React-compatible event handler names. Ensures proper camelCase formatting for React event handlers.

    Parameters

    • event_type: DOM event type enum value.

    Returns

    String - React-compatible event handler name with "on" prefix.
    inspect(dom_event_to_react_handler(KeyDown), content="onKeyDown") inspect(dom_event_to_react_handler(Click), content="onClick") inspect(dom_event_to_react_handler(MouseEnter), content="onMouseEnter") inspect(dom_event_to_react_handler(DoubleClick), content="onDoubleClick")

    ellipse

    fn ellipse(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, cx? : String, cy? : String, rx? : String, ry? : String, fill? : String, stroke? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the ellipse svg element.
    fn em(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the em semantic element.

    fieldset

    fn fieldset(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, name? : String, disabled? : Bool, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the fieldset form element.

    figcaption

    fn figcaption(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the figcaption semantic element.

    figure

    fn figure(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the figure semantic element.
    fn footer(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a footer element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing a footer element.

    form

    fn form(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], action? : FormAction, method_? : String, on_submit? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a React form. A function-valued action runs in a React Action and receives the submitted ReactFormData payload.

    form_action

    fn form_action(dispatch : (ReactFormData) -> Unit) -> FormAction

    Wraps a use_action_state dispatcher for a form action or submit-control formAction property.
    fn g(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, transform? : String, fill? : String, stroke? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the g svg element.
    fn h1(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an h1 element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing an h1 element.

    fn h2(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an h2 element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing an h2 element.

    fn h3(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an h3 element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing an h3 element.

    fn h4(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an h4 element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing an h4 element.

    fn h5(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an h5 element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing an h5 element.

    fn h6(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an h6 element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing an h6 element.

    fn header(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a header element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing a header element.

    hydrate_root

    fn hydrate_root(vdom : VirtualNode, parent :
    Element
    , options? : RootOptions) -> Unit

    Hydrates React-generated HTML already present in parent. The initial VDOM must produce identical markup. Later render calls reuse the hydrated root.

    img

    fn img(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , src? : String, alt? : String, width? : String, height? : String, on_click? : (DOMEvent) -> Unit, on_load? : (DOMEvent) -> Unit, on_error? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an img element with the specified attributes, event handlers, and image properties.

    Returns a virtual DOM node representing an img element.

    input

    fn input(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , type_? : InputType, name? : String, value? : String, default_value? : String, placeholder? : String, disabled? : Bool, read_only? : Bool, checked? : Bool, default_checked? : Bool, form_action? : FormAction, on_click? : (DOMEvent) -> Unit, on_change? : (DOMEvent) -> Unit, on_input? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an input element with the specified attributes, event handlers, and properties.

    Returns a virtual DOM node representing an input element.

    is_boolean_prop

    fn is_boolean_prop(prop_name : String) -> Bool

    Checks if a React property should be treated as a boolean attribute. Returns true for attributes that React expects as boolean values.

    Parameters

    • prop_name: React property name (already converted from DOM attribute).

    Returns

    Bool - true if the property should be treated as boolean.

    inspect(is_boolean_prop("checked"), content="true") inspect(is_boolean_prop("disabled"), content="true") inspect(is_boolean_prop("readOnly"), content="true") inspect(is_boolean_prop("className"), content="false")

    label

    fn label(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit, for_? : String) -> VirtualNode

    Creates a label element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing a label element.

    lazy_component

    fn[T] lazy_component(loader : async () -> ReactComponent[T]) -> ReactComponent[T]

    Defines a lazy typed component. Declare it outside render paths. React calls and caches loader on first render; the MoonBit async bridge resolves to the { default: component } module shape required by React.lazy.

    legend

    fn legend(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the legend form element.
    fn li(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a li (list item) element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing a li element.

    line

    fn line(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, x1? : String, y1? : String, x2? : String, y2? : String, stroke? : String, stroke_width? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the line svg element.

    linear_gradient

    fn linear_gradient(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, x1? : String, y1? : String, x2? : String, y2? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the linearGradient svg element.
    fn link(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, rel? : String, href? : String, media? : String, precedence? : String, cross_origin? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the link metadata element.

    main_

    fn main_(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the main semantic element.

    mask

    fn mask(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, x? : String, y? : String, width? : String, height? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the mask svg element.

    meta

    fn meta(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, name? : String, content? : String, charset? : String, http_equiv? : String, item_prop? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the meta metadata element.

    meter

    fn meter(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, value? : Float, min? : Float, max? : Float, low? : Float, high? : Float, optimum? : Float, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the meter form element.
    fn nav(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a nav element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing a nav element.

    obscure

    fn[T] obscure(v : T) ->
    JsObscure

    a short hand to turn value into JsObscure in hook deps
    fn ol(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates an ol (ordered list) element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing an ol element.

    optgroup

    fn optgroup(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, label? : String, disabled? : Bool, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the optgroup form element.

    option

    fn option(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, value? : String, disabled? : Bool) -> VirtualNode

    Creates an option element with the specified attributes and properties.

    Returns a virtual DOM node representing an option element.

    output

    fn output(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, name? : String, html_for? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the output form element.
    fn p(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a p element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing a p element.

    path

    fn path(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, d? : String, fill? : String, stroke? : String, stroke_width? : String, path_length? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the path svg element.

    polygon

    fn polygon(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, points? : String, fill? : String, stroke? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the polygon svg element.

    polyline

    fn polyline(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, points? : String, fill? : String, stroke? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the polyline svg element.

    pre

    fn pre(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the pre semantic element.

    progress

    fn progress(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, value? : Float, max? : Float, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the progress form element.

    radial_gradient

    fn radial_gradient(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, cx? : String, cy? : String, r? : String, fx? : String, fy? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the radialGradient svg element.

    rect

    fn rect(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, x? : String, y? : String, width? : String, height? : String, rx? : String, ry? : String, fill? : String, stroke? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the rect svg element.

    render

    fn render(vdom : VirtualNode, parent :
    Element
    ) -> Unit

    Renders a virtual DOM node to the specified parent element. Repeated calls for the same parent reuse its React root.

    render_to_string

    fn render_to_string(vdom : VirtualNode, identifier_prefix? : String) -> String

    Renders a React tree to an HTML string for basic synchronous SSR or SSG. This intentionally does not provide streaming or wait for suspended data.

    render_with_options

    fn render_with_options(vdom : VirtualNode, parent :
    Element
    , options : RootOptions) -> Unit

    Renders through a new root configured with React 19 root options. Options are consumed only when this call creates the root; later renders reuse it.

    script_tag

    fn script_tag(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, src? : String, type_? : String, cross_origin? : String, async_? : Bool, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the script metadata element.

    section

    fn section(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a section element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing a section element.

    select

    fn select(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], value? : String, values? : Array[String], default_value? : String, default_values? : Array[String], disabled? : Bool, multiple? : Bool, on_change? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a select element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing a select element.

    span

    fn span(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a span element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing a span element.

    Example:

    let _ = span(
    class_name="text-bold",
    on_click=fn(_e) { println("Clicked!") }, []
    )

    start_transition

    fn start_transition(action : () -> Unit) -> Unit

    Marks updates made by action as non-urgent without reading transition state. Use use_transition when the component also needs is_pending.

    static_style

    #callsite(autofill(loc))
    fn[U : Show] static_style(rules : Array[(U,
    RespoStyle
    )], loc~ : SourceLoc) -> String

    Declares a static style in the document head, for example:
    let style_demo : String = static_style(
    [("&", respo_style(margin=4 |> Px, background_color=Hsl(200, 90, 96)))],
    )

    stop

    fn stop(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, offset? : String, stop_color? : String, stop_opacity? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the stop svg element.

    strong

    fn strong(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the strong semantic element.

    style_tag

    fn style_tag(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, precedence? : String, href? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the style metadata element.

    summary

    fn summary(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the summary interactive element.

    suspense

    fn suspense(fallback : VirtualNode, children : Array[VirtualNode]) -> VirtualNode

    Creates a Suspense boundary that displays fallback until every child is ready, then reveals the children together.

    svg

    fn svg(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, view_box? : String, width? : String, height? : String, xmlns? : String, fill? : String, stroke? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the svg svg element.

    svg_text

    fn svg_text(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, x? : String, y? : String, dx? : String, dy? : String, text_anchor? : String, fill? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the text svg element.

    symbol

    fn symbol(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, view_box? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the symbol svg element.

    table

    fn table(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the table table element.

    tbody

    fn tbody(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the tbody table element.
    fn td(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, headers? : String, col_span? : Int, row_span? : Int, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the td table element.

    textarea

    fn textarea(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , value? : String, default_value? : String, placeholder? : String, rows? : Int, cols? : Int, disabled? : Bool, read_only? : Bool, on_change? : (DOMEvent) -> Unit, on_input? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a textarea element with the specified attributes, event handlers, and properties.

    Returns a virtual DOM node representing a textarea element.

    tfoot

    fn tfoot(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the tfoot table element.
    fn th(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, scope? : String, headers? : String, abbr? : String, col_span? : Int, row_span? : Int, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the th table element.

    thead

    fn thead(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the thead table element.

    time_

    fn time_(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, date_time? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the time semantic element.

    title

    fn title(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the title metadata element.
    fn tr(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the tr table element.

    tspan

    fn tspan(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, x? : String, y? : String, dx? : String, dy? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the tspan svg element.
    fn ul(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], innerHTML? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a ul (unordered list) element with the specified attributes, event handlers, and children.

    Returns a virtual DOM node representing a ul element.

    unmount

    fn unmount(parent :
    Element
    ) -> Unit

    Unmounts the React root associated with a parent element, if one exists. A later call to render or hydrate_root creates a fresh root.

    use_

    fn use_(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], role? : String, title? : String, tab_index? : Int, hidden? : Bool, aria_label? : String, data_testid? : String, href? : String, xlink_href? : String, x? : String, y? : String, width? : String, height? : String, on_click? : (DOMEvent) -> Unit) -> VirtualNode

    Generated typed helper for the use svg element.

    use_action_state

    fn[S, A] use_action_state(initial : S, action : (S, A) -> S) -> (S, (A) -> Unit, Bool)

    Stores state managed by a React 19 action. The action receives the current MoonBit state and its dispatched value, then returns the next state.

    React reports whether an action transition is pending in the final tuple value. Dispatch from a form action or start_transition when appropriate.

    use_async_action_state

    fn[S, A] use_async_action_state(initial : S, action : async (S, A) -> S) -> (S, (A) -> Unit, Bool)

    Stores state managed by an asynchronous React Action. The MoonBit async reducer is exported as a JavaScript Promise so React can keep is_pending true until it settles and can serialize queued Actions.

    use_callback0_deps

    fn use_callback0_deps(f : () -> Unit, deps : Array[
    JsObscure
    ]) -> (() -> Unit)

    use_callback_deps

    fn[F] use_callback_deps(callback : F, deps : Array[
    JsObscure
    ]) -> F

    use_context

    fn[T] use_context(context : ReactContext[T]) -> T

    Reads and subscribes to the nearest provider value for context. This is a React Hook and must only be called while rendering a component.

    use_deferred_value

    fn[T] use_deferred_value(value : T) -> T

    Defers a value so that urgent updates can render before expensive consumers of that value. The returned value keeps the original MoonBit type.

    use_dom_ref

    fn use_dom_ref() -> ReactDomRef

    Creates a nullable DOM ref Hook.

    Call this only at the top level of a React component or another Hook.

    use_effect_cleanup_deps

    fn use_effect_cleanup_deps(effect : () -> (() -> Unit), deps : Array[
    JsObscure
    ]) -> Unit

    Runs an effect with dependencies and registers its returned cleanup function.

    use_effect_deps

    fn use_effect_deps(effect : () -> Unit, deps : Array[
    JsObscure
    ]) -> Unit

    use_effect_event

    fn[F] use_effect_event(callback : F) -> F

    Creates a non-reactive callback for use from an effect. The callback always observes the latest props and state without becoming an effect dependency. React requires effect events to be invoked only from effects.

    use_effect_once

    fn use_effect_once(effect : () -> Unit) -> Unit

    use_effect_once_with_cleanup

    fn use_effect_once_with_cleanup(effect : () -> (() -> Unit)) -> Unit

    Runs an effect once and registers its returned cleanup function.

    use_form_status

    fn use_form_status() -> FormStatus

    use_id

    fn use_id() -> String

    Returns a stable identifier suitable for associating component-local DOM elements, such as a label and its input.

    use_imperative_handle_deps

    fn[T] use_imperative_handle_deps(handle_ref : ImperativeRef[T], create_handle : () -> T, deps : Array[
    JsObscure
    ]) -> Unit

    Exposes a typed imperative handle through a nullable imperative ref.

    React assigns Some(handle) after commit and restores None on cleanup. In React 19 the ref can be carried in ordinary typed component props, so a forwardRef wrapper is not required.

    use_imperative_ref

    fn[T] use_imperative_ref() -> ImperativeRef[T]

    Creates an empty typed imperative ref. Pass it through typed component props and bind it inside the child with use_imperative_handle_deps.

    use_layout_effect_cleanup_deps

    fn use_layout_effect_cleanup_deps(effect : () -> (() -> Unit), deps : Array[
    JsObscure
    ]) -> Unit

    Runs a layout effect with dependencies and registers its returned cleanup function. Prefer this only when the effect must run before the browser paints.

    use_layout_effect_deps

    fn use_layout_effect_deps(effect : () -> Unit, deps : Array[
    JsObscure
    ]) -> Unit

    use_memo_deps

    fn[A] use_memo_deps(factory : () -> A, deps : Array[
    JsObscure
    ]) -> A

    use_optimistic

    fn[S, A] use_optimistic(value : S, reducer : (S, A) -> S) -> (S, (A) -> Unit)

    Returns a temporary optimistic state and a typed dispatcher. React restores the supplied base value when the surrounding Action finishes unless the owner commits a new base value.

    use_reducer

    fn[S : Default, A] use_reducer(initial? : S, reducer : (S, A) -> S) -> (S, (A) -> Unit)

    Compatibility reducer helper with an optional initial state. Prefer use_reducer_with_initial for new code so the state type need not derive Default.

    use_reducer_with_initial

    fn[S, A] use_reducer_with_initial(initial : S, reducer : (S, A) -> S) -> (S, (A) -> Unit)

    Creates a reducer with an explicit initial state. Unlike the compatibility use_reducer overload, this accepts state types that do not implement Default.

    use_ref

    fn[T] use_ref(initial : T) -> ReactRef[T]

    Creates a React ref Hook with an explicit initial value.

    Call this only at the top level of a React component or another Hook. For a DOM element ref with a safe empty state, prefer use_dom_ref.

    use_state

    fn[T] use_state(initial : T) -> (T, (T) -> Unit)

    use_state_with_updater

    fn[T] use_state_with_updater(initial : T) -> (T, (StateUpdate[T]) -> Unit)

    Like use_state, but its setter supports functional updates through StateUpdate::Update. Prefer this form when the next state depends on the previous value and React may batch or defer updates.

    use_sync_external_store

    fn[T] use_sync_external_store(subscribe : (() -> Unit) -> (() -> Unit), get_snapshot : () -> T, get_server_snapshot? : () -> T) -> T

    Reads and subscribes to a typed immutable snapshot from an external store.

    subscribe must return an unsubscribe callback and should keep stable identity across renders. Repeated get_snapshot calls must return the same value while the store has not changed. Supply get_server_snapshot when the component can render on the server; its initial value must also match during hydration.

    use_transition

    fn use_transition() -> (Bool, (() -> Unit) -> Unit)

    Marks state updates made by action as non-urgent. The returned boolean is true while React is rendering the transition.

    video

    fn video(id? : String, class_name? : String, class_list? : Array[String], attrs? : ElementAttrs, event? : ElementEvents, style? :
    RespoStyle
    , children : Array[VirtualNode], src? : String, controls? : Bool, autoplay? : Bool, loop_enabled? : Bool, muted? : Bool, width? : String, height? : String, on_click? : (DOMEvent) -> Unit, on_play? : (DOMEvent) -> Unit, on_pause? : (DOMEvent) -> Unit) -> VirtualNode

    Creates a video element with the specified attributes, event handlers, and video properties.

    Returns a virtual DOM node representing a video element.