function / @typed/ui/Collection

makeState

Creates hydrated Collection state. The collection starts with the supplied immutable item array, or empty.

Learn this UI primitive →

Package version
1.0.0-beta.13
Category
Collection state
Since
1.0.0

Import

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

Signatures

export declare function makeState<Value = unknown, Element extends object = globalThis.Element>(initial?: State<Value, Element>): Effect.Effect<RefSubject.RefSubject<State<Value, Element>>, never, Scope.Scope>;

Why

State and collection ownership can be composed and tested independently from any renderer.

Ownership and lifetime

The returned Effect creates the RefSubject when run. That state is renderer-independent; collection registrations belong to the separate Scope that runs register or ref, not to state creation.

Examples

import * as Effect from "effect/Effect";
import * as Collection from "@typed/ui/Collection";

const program = Effect.scoped(
  Effect.gen(function* () {
    const collection = yield* Collection.makeState<string>();
    return yield* collection;
  }),
);

Other public imports

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

Source