@serenis/uid
v3.66.0
Published
Generates opaque, URL-safe unique identifiers for client-side use. Built on [nanoid](https://github.com/ai/nanoid).
Keywords
Readme
@serenis/uid
Generates opaque, URL-safe unique identifiers for client-side use. Built on nanoid.
Quick start
yarn workspace @serenis/uid build
yarn workspace @serenis/uid test
yarn workspace @serenis/uid typecheckimport { uid } from '@serenis/uid'
const toastId = uid() // e.g. "k3m9ab12cd5efg78"API
uid(): string
Returns a 16-character random string from the alphabet 1234567890abcdefghikjlmnopqrstuvwxyz (digits and lowercase a-z).
- Not tied to any React tree or DOM node.
- Safe to use as a map key, localStorage key, or correlation token.
When to use what
Use useId() when the ID is bound to the React tree or the DOM. Use uid() for any other generic identifier.
| Need | Use |
| --------------------------------------------------------------------------------------- | ------------------------- |
| Stable ID for a DOM node, htmlFor, aria-*, SVG <defs>, or scoped CSS class | useId() from React |
| Opaque key that survives remounts or must be stored (toast, fingerprint, session token) | uid() from this package |
