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;Parameters
Section titled “Parameters”| ctor | new (…args: Args) => TScope | |
| args | Args |
Returns
Section titled “Returns”TScope
Remarks
Section titled “Remarks”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.
Example
Section titled “Example”function MyScope(props) {
const parentScope = useScope();
const scope = createScope(MyScope, "scope-name", parentScope);
return <Scope value={scope}>{props.children}</Scope>;
}