Rendering
mount(component, target)
Mount a component to a DOM element. Returns a ViewApp with a dispose method to unmount and clean up:
import { mount } from "@hedystia/view";
function App() {
return <h1>Hello, world!</h1>;
}
const app = mount(App, document.getElementById("root")!);ViewApp
interface ViewApp {
dispose: () => void;
root: Owner | null;
}Calling dispose() runs all cleanup callbacks, removes children from the target element, and tears down the reactive graph:
// Mount
const app = mount(App, document.getElementById("root")!);
// Unmount later
app.dispose();Re-mounting
Mounting clears the target element first, so you can re-mount to the same target:
mount(PageA, root);
// Later...
mount(PageB, root); // clears PageA, mounts PageBhydrate(component, target)
Connect a component to existing server HTML without clearing the target:
import { hydrate } from "@hedystia/view";
const app = hydrate(Counter, document.getElementById("counter")!);Hydration adopts compatible native elements and text, connects events and reactive bindings, and returns the same ViewApp lifecycle as mount. Mount hooks run after adoption. Calling dispose() releases listeners and reactive owners and clears the target; repeated disposal is safe.
Live form values, checkboxes, select choices, focus and selection survive the first activation. Later signal updates apply their new values normally. Keep initial server and client markup consistent: mismatches are repaired locally, and state in replaced elements cannot be preserved. Use ref callbacks for imperative access to adopted native elements.
This is a one-time native DOM adoption. View retains no virtual DOM render tree and runs no tree diff on reactive updates. See static builds and islands for automatic island activation and Astro integration.
renderToString(component)
Render a component to an HTML string for server-side rendering (SSR):
import { renderToString } from "@hedystia/view";
function Page() {
return (
<html>
<head><title>SSR</title></head>
<body><h1>Hello from the server</h1></body>
</html>
);
}
const html = renderToString(Page);
// "<html><head><title>SSR</title></head><body><h1>Hello from the server</h1></body></html>"Note:
renderToStringcreates a one-time snapshot. Signals and effects are not active in the resulting string.
