[]previous and next page

createComponent (@shadow-js/web/server)

Calls a component on the server, untracked, with its own owner and hydration scope, so the hydration keys it hands out depend only on where it sits in the tree.

Calls a component on the server, untracked, with its own owner and hydration scope, so the hydration keys it hands out depend only on where it sits in the tree. The server twin of the client createComponent: compiled server output calls it for <Component />, and a hand-written render entry calls it for the root component.

Import#

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

Signature#

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

Parameters#

Name Description
component The component function.
props The props object; reactive props are getters.

Returns#

Whatever the component returns.

Throws#

  • TypeError when component is not a function. An error the component throws propagates.

Examples#

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

function Card(props: { title: string }) {
  return <h2>{props.title}</h2>;
}
const html = renderToString(() => createComponent(Card, { title: "Hello" }));