CreateScopes type
Home > @rimitive/view > CreateScopes
CreateScopes type
Section titled “CreateScopes type”Public scope API for managing element lifecycles and cleanup.
Signature:
export type CreateScopes = { disposeScope: <TElement = object>(scope: RenderScope<TElement>) => void; createElementScope: <TElement extends object = object>(element: TElement, fn: () => void) => RenderScope<TElement> | null; scopedEffect: (fn: () => void | (() => void)) => () => void; onCleanup: (cleanup: () => void) => void; getElementScope: <TElement extends object>(element: TElement) => RenderScope<TElement> | undefined;};References: RenderScope
Example
Section titled “Example”import { createScopes, type CreateScopes } from '@rimitive/view/deps/scope';
const scopes: CreateScopes = createScopes({ baseEffect: effect });
// Use in element creationconst scope = scopes.createElementScope(element, () => { scopes.scopedEffect(() => { console.log('Reactive effect'); }); scopes.onCleanup(() => { console.log('Cleanup when element is removed'); });});