How to Generate UUIDs in React

Generate UUIDs in React code with browser or runtime APIs for v4 and a package such as uuid for v7, but keep IDs stable outside render.

Important: do not generate random UUIDs for React list keys during render. Keys must be stable across renders.

How to generate UUID v4 in React code

const id = crypto.randomUUID();

Generate the value when creating data, not while rendering a list item key.

How to generate UUID v7 in React code

import { v7 as uuidv7 } from 'uuid';

const id = uuidv7();

Native support notes

  • React does not define its own UUID API.
  • UUID v4 often comes from browser crypto support.
  • UUID v7 is usually package-based.
  • Stable keys matter more than the specific UUID version when rendering lists.

Practical notes

  • Generate UUIDs when records are created, fetched, or normalized, not inside JSX mapping expressions.
  • Use UUID v7 if your client-generated IDs later benefit from chronological ordering on the backend.
  • See the JavaScript guide for runtime details.

Frequently Asked Questions

Yes, but only if the UUIDs are stable and belong to the data itself. Do not generate a new UUID on every render.

Use crypto.randomUUID() for simple v4 needs in modern browsers. Use a package when you need UUID v7 or consistent behavior across multiple runtimes.

Learn more

These articles expand on related concepts, formats and practical considerations.

By using this site, you agree to our Privacy Policy and Terms of Service. You are not permitted to use the GUIDs (also known as UUIDs) generated by this site or use any other content, services and information available if you do not agree to these terms.
Disclaimer: All information is provided for general educational and technical reference only. While we aim to keep the content accurate, current and aligned with published standards, no guarantees are made regarding completeness, correctness or suitability for any specific use case.
GUID specifications, best practices, security guidance, database behavior and ecosystem conventions (including cloud platforms and identifier formats) may change over time or differ by implementation. Examples, recommendations and comparisons are illustrative and may not apply universally.
This content should not be considered legal, security, compliance or architectural advice. Before making critical design, security or production decisions, always consult the latest official standards and vendor-specific documentation.
Always evaluate behavior in your own environment.
Standards Compliance: The GUIDs generated by this site conform to RFC 4122 and RFC 9562 specifications whenever possible, using cryptographically secure random number generation.