stax-monorepo
    Preparing search index...

    Variable UniqueIdConst

    UniqueId: {
        IdGenerator: typeof IdGenerator;
        make: (prefix?: string) => Effect<string>;
        makeIdGeneratorLayer: () => Layer<IdGenerator>;
    } = ...

    Generate unique IDs for DOM elements. Useful for ARIA relationships, label associations, and other cases where elements need to reference each other by ID.

    On SSR'd apps, mount / hydrate / toHttpRoutes / buildStaticSite each provide an IdGenerator whose counter is scoped to that render — so server and client agree on ids and ARIA wiring survives hydration.

    Type Declaration

    • IdGenerator: typeof IdGenerator
    • make: (prefix?: string) => Effect<string>

      Generate a unique ID, optionally with a prefix. Draws from the scoped IdGenerator when one is provided (always true inside mount / hydrate / SSR / SSG), falls back to a module-global counter otherwise.

    • makeIdGeneratorLayer: () => Layer<IdGenerator>

      Build a fresh IdGenerator layer. Each call creates its own counter starting at zero. Entry points that render a tree once (mount, hydrate, per-SSR-request, per-SSG-page) call this to get an isolated counter.

    // Basic usage
    const id = yield* UniqueId.make()
    // => "uid-1"

    // With prefix
    const contentId = yield* UniqueId.make("collapsible-content")
    // => "collapsible-content-1"

    // For ARIA relationships
    Effect.gen(function* () {
    const labelId = yield* UniqueId.make("label")
    const inputId = yield* UniqueId.make("input")

    return yield* $.div([
    $.label({ id: labelId, htmlFor: inputId }, "Name"),
    $.input({ id: inputId, "aria-labelledby": labelId }),
    ])
    })