Generate a short random ID. Client-safe, no crypto dependency.
export function randomId(prefix = ''): string {
const id = Math.random().toString(36).slice(2, 11);
return prefix ? `${prefix}-${id}` : id;
}
Short random string (alphanumeric). Optional prefix for readability (e.g. 'item-abc123'). Not cryptographically secure.
React keys, DOM ids, or temporary identifiers.
id={randomId('input')} or key={randomId()}