# ref

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

## Signatures

```ts
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](https://tylors.github.io/typed/reference/symbols/QHR5cGVkL3VpL0NvbGxlY3Rpb24jbWFrZVN0YXRl/). 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.
