mountComponent attaches a Solar component to a DOM container and starts the reactivity loop. It renders the component’s initial vnode tree into the container, wires up any hooks declared inside render, and returns a numeric instance ID you use to refer to that mounted instance. Call unmountComponent with that ID to remove the component from the DOM and run all cleanup callbacks.
mountComponent
Parameters
A component function returned by
defineComponent(). Solar checks the _isComponent flag and throws a ContractError if you pass a plain function. The component must also be registered via registry.register() before mounting — mountComponent throws a ContractError if it isn’t.The initial props to pass to the component. Solar validates these against the component’s schema, applying the same
ContractError behaviour as a direct component call.The DOM element to render into. Solar appends the component’s root DOM node as a child of this element (or inserts it at
index if provided).The child index within
container at which to insert the component’s root node. Defaults to 0. Useful when you mount multiple components into the same container and need to control their order.Return value
A unique numeric instance ID for this mounted component. Store this value — you pass it to
unmountComponent() to remove the component later.unmountComponent
Parameters
The instance ID returned by the corresponding
mountComponent() call. If no instance with this ID exists, unmountComponent returns silently without throwing.unmountComponent removes the component’s root DOM node from its container and runs every cleanup callback registered during the component’s lifetime — including onUnmount lifecycle callbacks, useSubscription detachments, and cancellation of in-flight useResource requests.
Examples
unmountComponent runs all cleanup callbacks registered during the component’s lifetime — onUnmount lifecycle callbacks, useSubscription detachments, and useResource fetch cancellations — in the order the hooks were declared in render. After cleanup, the component’s root DOM node is removed from the container and the instance is deleted from Solar’s internal registry.