Skip to content

Make moment an optional dependency #2220

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

Closed
wants to merge 2 commits into from
Closed

Make moment an optional dependency #2220

wants to merge 2 commits into from

Conversation

frw
Copy link
Contributor

@frw frw commented Aug 27, 2022

Description

This PR makes the moment package an optional dependency so as to decrease bundle size for those that do not use moment to format date/time.

Potentially breaking change: Projects that do not have moment as a direct dependency will find when upgrading that the supplied dateFormat/timeFormat would no longer have any effect on the displayed date/time, although there will be an error message logged to console to indicate that this is happening.

Tested by running the example app and ensured the dates/times are still rendered properly
Screenshot_20220827-171143_R N U I L I B

Changelog

Make moment an optional dependency

Copy link
Collaborator

@M-i-k-e-l M-i-k-e-l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @frw,
Thanks a lot for the contribution!
I've added a small comment (please let me know if you do not have the capacity to fix that).

In any case we cannot merge this into master IMO since it's a breaking change, but we should definitely merge it for the next major release.

return value.toLocaleDateString();
}
if (!moment) {
console.error(`RNUILib DateTimePicker component with dateFormat requires installing "moment" dependency`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding this and the other error to a useEffect (either the existing one or a new one with [dateFormat, timeFormat] as a dependency array) will simplify the code and make it more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @M-i-k-e-l,

Thanks for reviewing. Definitely makes sense to have it in the next major release.
I've made the changes to the code as you've suggested. Let me know if there's anything else you'd like me to change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@M-i-k-e-l M-i-k-e-l added the V7 label Sep 4, 2022
@M-i-k-e-l
Copy link
Collaborator

M-i-k-e-l commented Sep 5, 2022

Internal note: look at unifying with #1805

@dougg0k
Copy link

dougg0k commented Jan 30, 2023

Why not replace with a better option like https://day.js.org/ or even https://date-fns.org/ if dayjs are no longer enough.

@M-i-k-e-l
Copy link
Collaborator

@frw
Thanks a lot for your contribution; apologies, but we will be merging this as part of our v7 (link), so unfortunately you'll not get the due credit, hope it's ok.

@dougg0k, I think this component will be replaced so I am not sure we want to invest in this further.

@M-i-k-e-l M-i-k-e-l closed this Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants