[]previous and next page

createComponent

Calls a component untracked, under a new owner that is a child of the current one: cleanups and effects it creates are disposed with the enclosing scope.

Calls a component untracked, under a new owner that is a child of the current one: cleanups and effects it creates are disposed with the enclosing scope. The name, given in development builds, is recorded for devtools.

Import#

ts
import { createComponent } from "@shadow-js/web";

Signature#

ts
function createComponent<P>(
  component: (props: P) => unknown,
  props: P,
  name?: string,
): unknown

Parameters#

Name Description
component The component function.
props The props object (usually with getters for reactive props).
name Optional devtools name.

Returns#

Whatever the component returns.

Examples#

ts
import { createComponent } from "@shadow-js/web";

function Counter(props: { start: number }) {
  return `Count: ${props.start}`;
}

const view = createComponent(Counter, { start: 0 }, "Counter");