Comparing
2KB immutable date time library alternative to Moment.js with the same modern API
Create your next immutable state by mutating the current one
| Metric | dayjs | immer |
|---|---|---|
| Ecosystem | npm | npm |
| Difficulty | Intermediate | Beginner ✓ |
| Weekly downloads | 43.9M↑ | 41.7M |
| Latest version | v1.11.20 | v11.1.4 |
| Recipes | 1 | 1 |
dayjs only
Shared
immer only
Use Day.js when you need date parsing, formatting, arithmetic (add/subtract days/months), or comparisons in browser code where bundle size matters. Its plugin system covers timezones, relative time ('3 hours ago'), duration, and ISO weeks.
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.
For complex timezone-aware calendar applications, consider Temporal (the upcoming TC39 proposal) or date-fns with explicit timezone handling. Day.js's plugin system can grow large if you need many features.
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().
dayjs
immer