Skip to content

createScope

Construct a scope instance and register it with devtools. Prefer this over calling new directly so that debugging tools can track the scope.

import { createScope } from "@alloy-js/core";
function createScope<TScope extends OutputScope, Args extends unknown[]>(ctor: new (...args: Args) => TScope, ...args: Args): TScope;
ctornew (…args: Args) => TScope
argsArgs

TScope

Inside a component, obtain the current scope with useScope() and pass it as the parentScope constructor argument so the new scope is wired into the scope tree.

function MyScope(props) {
  const parentScope = useScope();
  const scope = createScope(MyScope, "scope-name", parentScope);
  return <Scope value={scope}>{props.children}</Scope>;
}