Comparing
Create your next immutable state by mutating the current one
RFC9562 UUIDs
| Metric | immer | uuid |
|---|---|---|
| Ecosystem | npm | npm |
| Difficulty | Beginner ✓ | Intermediate |
| Weekly downloads | 41.7M | 242.6M↑ |
| Latest version | v11.1.4 | v13.0.0 |
| Recipes | 1 | 7↑ |
immer only
Shared
uuid only
Use Immer whenever you have deeply nested state updates that are painful to write immutably: Redux reducers, Zustand's set function, or React useState with complex objects. It's built into Redux Toolkit's createSlice, so you're probably already using it.
Use uuid whenever you need a unique ID that doesn't require a database sequence: primary keys in distributed systems, idempotency keys for API calls, session tokens, file names, or correlation IDs for logging.
For flat, simple state (a counter, a boolean toggle), immer's overhead isn't worth it — just spread the object. Immer also has edge cases with classes, Maps, and Sets that require using enableMapSet() and enableAllPlugins().
For database primary keys where you control the DB, auto-incrementing integers are smaller and faster to index. For sortable unique IDs (e.g. for pagination), consider ULID or UUIDv7, which encode a timestamp prefix.
immer
uuid
+3 more