hypeserver / react-date-range

A React component for choosing dates and date ranges.
MIT License
2.59k stars 672 forks source link

Why is date-fns a peer dependency? #356

Closed RareSecond closed 3 years ago

RareSecond commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

nghiepdev commented 2 years ago

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} />
)