[]previous and next page

enterComponent

Runs a component call in a scope of its own, so the keys it draws depend only on its position among its parent's calls: what createComponent does on the client and on the server.

Runs a component call in a scope of its own, so the keys it draws depend only on its position among its parent's calls: what createComponent does on the client and on the server. The component's scope takes the next number of the parent scope.

Import#

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

Signature#

ts
function enterComponent<T>(fn: () => T): T

Parameters#

Name Description
fn The component call, run synchronously, once.

Returns#

What fn returns. Without a scope in effect, fn simply runs.

Examples#

ts
import { createRootScope, enterComponent, nextKey, withScope } from "@shadow-js/web/extend";

withScope(createRootScope(), () => {
  nextKey(); // "0-0"
  return enterComponent(() => nextKey()); // "0-1-0": the component's first key
});