R
fn

useId

v0.0.14testeddemo

SSR-safe unique identifier. Thin wrapper around Vue 3.5's built-in `useId()` that accepts an optional prefix and allows callers to pass a pre-existing id (useful for primitives that accept a user-supplied `id` prop).

Examples

ts
const id = useId();
// => 'robonen-v-1'
ts
const id = useId(() => props.id, 'dialog');
// => props.id ?? 'dialog-v-1'

Demo

Loading demo…

Signature

ts
export function useId(
  deterministic?: MaybeRefOrGetter<string | undefined>,
  prefix = 'robonen',
): ComputedRef<string>{ ... }

Parameters

ParameterTypeDescription
deterministic?MaybeRefOrGetter<string | undefined>Existing id to return if provided
prefix?stringPrefix appended before the generated id (ignored when `deterministic` is set)

Returns

ComputedRef<string>A stable, SSR-safe id that matches between server and client