Comparison with MomentJs
- Problems with Moment.js:
- It is highly based on OOP APIs, which makes it fail to work with tree-shaking, thus leading to a huge bundle size and performance issues.
- It is mutable and it causes bugs
- Complex OOP API (which doubles mutability problem)
- Advantages of date-fns
- Function per file
- Date-fns library consists of a variety of functions, and it allows you to import these functions individually as needed, which reduces the applications package size drastically
- Immutable
- Provide a new JavaScript date object instance from each function
- Fast and Compact
- Function per file
Refs:
Date-fns vs MomentJS: Choosing the Right Date Utility Library