Skip to Content
⭐️ Leave a star →
HooksuseId

useId

Returns a stable, SSR-safe unique id with an optional human-readable prefix. Wraps React’s useId and strips characters that aren’t valid in CSS selectors. Pass a staticId as the second argument to honor an id provided by the parent instead of generating one.

import { useId } from '@wire-ui/react' function Field({ id, label, ...props }: { id?: string; label: string }) { const inputId = useId('field', id) const labelId = useId('field-label') return ( <> <label id={labelId} htmlFor={inputId}>{label}</label> <input id={inputId} aria-labelledby={labelId} {...props} /> </> ) }

Parameters

ParamTypeDescription
prefixstringHuman-readable prefix prepended to the generated id. Defaults to 'wire'.
staticIdstringIf provided, returned as-is — the generated id is discarded.

Returns

A string id that is stable across renders and unique across the page.

Last updated on

MIT License © 2026 wire-ui

useId – Wire UI