function / @typed/ui

Collection.ref

Registers a mounted element and removes it automatically with the Scope in which the returned Effect is run.

Learn this UI primitive →

Package version
1.0.0-beta.7
Category
Item registration
Since
1.0.0
Member of
Collection

Import

import { Collection } from "@typed/ui";

Access Collection.ref through the imported Collection export. Its declaration below describes the member.

This public exposure is a re-export. Its import path is supported; declaration documentation is shared with the other public exposures below.

Signatures

export declare function ref<Value, Element extends object, E, R>(collection: RefSubject.RefSubject<State<Value, Element>, E, R>, item: Omit<Item<Value, Element>, "element">): (element: Element) => Effect.Effect<void, E, R | Scope.Scope>;

Why

The operation exposes Collection’s transition directly so callers can compose it in Effect programs and native event handlers.

Ownership and lifetime

Registration is owned by the Scope in which the registration Effect runs. Closing that Scope removes the exact registered item; creating the collection or state does not own this cleanup.

Example

Import with import { ref } from "@typed/ui/Collection"; Extend the Collection.makeState runnable setup. Inside the linked Effect program create const attach = ref(collection, { id: "save", value: "save" }), then run yield* attach(document.createElement("button")) and read the collection before Scope close.

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source