ReactConf 2025 in Henderson, Nevada featured the React core team and community presenting React 19 features and patterns. UUID generation in React was a recurring theme — the hydration mismatch problem affects any application that generates random IDs in server-rendered components, and React 19 server actions provide the clean solution. See UUID in React and Next.js for the full implementation guide.
Session: The hydration mismatch problem
// ❌ WRONG — generates different UUID on server and client
function OrderForm() {
const orderId = uuidv7(); // Different value each render!
return <input name="orderId" defaultValue={orderId} />;
}
// ✓ CORRECT — useRef persists the ID across renders on the client
function OrderForm() {
const orderId = useRef(uuidv7()).current;
return <input name="orderId" defaultValue={orderId} />;
}
// ✓ BEST — generate on server, pass as prop
// Server component (Next.js App Router):
export default async function OrderPage() {
const orderId = uuidv7(); // runs on server only
return <OrderForm orderId={orderId} />;
}
Session: React 19 Server Actions + UUID v7
// app/actions.ts — 'use server' runs exclusively on the server
'use server';
import { v7 as uuidv7 } from 'uuid';
import { db } from './db';
export async function createOrder(formData: FormData) {
const order = {
id: uuidv7(), // always server-side — no hydration risk
customerId: formData.get('customerId') as string,
total: Number(formData.get('total')),
};
await db.insert(orders).values(order);
return { orderId: order.id };
}
// app/orders/page.tsx
'use client';
import { createOrder } from '../actions';
export default function OrderPage() {
return (
<form action={createOrder}>
<input name="customerId" required />
<input name="total" type="number" required />
<button>Create Order</button>
</form>
);
}
React 19 server actions always execute on the server — uuidv7() never runs on the client. See UUID Generation Strategies.
Session: UUID v7 in Zustand stores
// stores/orderStore.ts
import { create } from 'zustand';
import { v7 as uuidv7 } from 'uuid';
interface OrderStore {
pendingOrders: Array<{ id: string; total: number }>;
addOrder: (total: number) => string;
}
export const useOrderStore = create<OrderStore>((set) => ({
pendingOrders: [],
addOrder: (total) => {
const id = uuidv7(); // client-side only — Zustand is never SSR'd
set((state) => ({
pendingOrders: [...state.pendingOrders, { id, total }],
}));
return id;
},
}));
Zustand stores run only on the client — UUID v7 generation in store actions is safe because Zustand is never server-rendered. The returned ID can be used for optimistic UI updates before the server confirms. See UUID as Idempotency Keys.
Session: Next.js App Router patterns
// app/api/orders/route.ts — server-only API route
import { NextResponse } from 'next/server';
import { v7 as uuidv7 } from 'uuid';
export async function POST(request: Request) {
const body = await request.json();
const order = { id: uuidv7(), ...body };
await db.insert(orders).values(order);
return NextResponse.json(order, { status: 201 });
}
The session demonstrated that Next.js API routes and server actions both run exclusively on the server — the uuid package is never bundled into the client JavaScript. See UUID in React and Next.js.
Further reading
- UUID in React and Next.js — hydration patterns
- UUID Generation Strategies — server vs client
- UUID as Idempotency Keys
- Opaque Identifier — UUID design principle
External references
Frequently asked questions
What is the UUID hydration mismatch problem in React?
If you call uuidv7() or crypto.randomUUID() inside a React component that renders on both server and client, the server and client generate different UUID values — React's reconciliation detects the mismatch and logs a hydration error. The fix is to generate UUIDs server-side only: in React 19 server actions, Next.js API routes, or with useEffect on the client for client-only IDs. See UUID in React and Next.js.
Should I use React's useId() instead of UUID?
useId() generates hydration-stable IDs for accessibility (ARIA labels, htmlFor associations) — not for database primary keys or API payloads. It produces an opaque string like :r0: that is unique within the component tree but not globally unique across requests. Use UUID v7 for all IDs that leave the React component (database keys, API payloads, idempotency keys). See Opaque Identifier.