question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plugins: how extend only one instance of dayjs?

See original GitHub issue

I’m evaluating this library for react-day-picker and I have a concern about plugins.

For what I understand, extending dayjs with plugins will affect all the instances of dayjs.

E.g. if I extend dayjs with weekOfYear plugin, the dayjs instances used by an application implementing react-day-picker+dayjs will be extended too. Is it correct? If yes, how to extend just one instance of dayjs?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

13reactions
gpblcommented, Aug 13, 2019

Thanks @iamkun for your answer,

I don’t agree much with this design choice. Not that I expect it giving practical problems for now, but an external component using dayjs would alter how dayjs works in the whole app. This doesn’t sound correct to me. What I would have preferred is a factory like:

const dayjs = dayjs.factory();
dayjs.extend(aPlugin); // only this instance of dayjs will use `aPlugin`

Just my feedback! Thanks for your work on dayjs!

9reactions
iamkuncommented, Aug 13, 2019

Thanks. To keep only one type of dayjs might be better I think. 😊

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Complete Guide to Day.js - Mirza Leka - Medium
Custom Parse Format extends dayjs() the constructor to support custom formats of input strings. Basically, it allows us to pass the date format ......
Read more >
How to use the dayjs.extend function in dayjs
To help you get started, we've selected a few dayjs examples, based on popular ways it is used in public projects. ; "dayjs";...
Read more >
Plugin
A plugin is an independent module that can be added to Day.js to extend functionality or add new features. By default, Day.js comes...
Read more >
How can I export a plugin from dayjs() in Javascript?
import isToday from "dayjs/plugin/isToday"; export dayjs.extend(isToday);. javascript · reactjs · typescript · dayjs.
Read more >
dayjs
Start using dayjs in your project by running `npm i dayjs`. ... A plugin is an independent module that can be added to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found