Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is date-fns a peer dependency? #356

Closed
RareSecond opened this issue Mar 16, 2020 · 5 comments
Closed

Why is date-fns a peer dependency? #356

RareSecond opened this issue Mar 16, 2020 · 5 comments

Comments

@RareSecond
Copy link

Subject of the issue

What's the exact reasoning behind having date-fns as a peer dependency? This really forces users to have this in their project, while they may not use any/may use another date library.

Also, what's the reasoning behind the choice for date-fns? Was this chosen arbitrarily, or is there a specific reason?

When you compare date-fns to other libraries (e.g. dayjs), you see that there's a huge difference in size.
https://bundlephobia.com/result?p=date-fns@2.11.0
https://bundlephobia.com/result?p=dayjs@1.8.22

@onionhammer
Copy link
Collaborator

onionhammer commented Oct 30, 2020

I'm curious if date-fns would be easier to remove unused date-fns functions if references were included as

import addDays from 'date-fns/addDays'

instead of

import { addDays } from 'date-fns'

https://date-fns.org/v2.16.1/docs/ECMAScript-Modules

@onionhammer
Copy link
Collaborator

onionhammer commented Nov 10, 2020

All of date-fns functions are being included in a default CRA app, because the includes are not using the esm feature available with date-fns. If you import functions used explicitly, rather than wildcard import, the bundle size will be significantly smaller.

image

@kamyar
Copy link
Contributor

kamyar commented May 29, 2021

Hey all, thank you for raising it and the fix.
I just merged #429 and we will make a release hopefully this week. :)

(And sorry for the delay, we are discussing how to improve the project maintenance)

@kamyar kamyar closed this as completed May 29, 2021
@kamyar
Copy link
Contributor

kamyar commented May 30, 2021

This has been release as 1.1.4
Please give it a try and let us know if there is any concerns. :)

@nghiepdev
Copy link

date-fns or dayjs should be an individual choice.

For example, we can:

import AdapterDateFns from 'react-date-range/AdapterDateFns';
// import AdapterDayjs from 'react-date-range/AdapterDayjs';

return (
 <DateRangePicker adapter={AdapterDateFns} />
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants