Skip to content

component()

Define a component with a setup function.

function component<P extends Record<string, any>>(
setup: (props: P) => WhisqNode
): ComponentDef<P>
ParamTypeDescription
setup(props: P) => WhisqNodeSetup function — runs once, returns UI

ComponentDef<P> — a callable that accepts props and returns a WhisqNode.

import { signal, component, div, button, span, mount } from "@whisq/core";
const Counter = component((props: { initial?: number }) => {
const count = signal(props.initial ?? 0);
return div(
button({ onclick: () => count.value-- }, "-"),
span(() => ` ${count.value} `),
button({ onclick: () => count.value++ }, "+"),
);
});
mount(Counter({ initial: 10 }), document.getElementById("app")!);