We may choose to not fix bugs or behavioral quirks, especially if they are long-standing known issues.We will not be making any major changes (no version 3).We will not be addressing tree shaking or bundle size issues.We will not be changing Moment's API to be immutable.We will not be adding new features or capabilities.We now generally consider Moment to be a legacy project in maintenance mode. We would also like to promote the Temporal addition to the JavaScript language, which is looking for feedback and contributors. Instead, we would like to recommend alternatives that are excellent choices for use in modern applications today. We recognize that many existing projects may continue to use Moment, but we would like to discourage Moment from being used in new projects going forward. The Moment team has discussed these issues at length. 4 alternatives to moment.js for internationalizing dates.You Probably Don't Need Moment.js Anymore.Recently, Chrome Dev Tools started showing recommendations for replacing Moment for the size alone. Libraries like Luxon (and others) take advantage of this, reducing or removing the need to ship your own data files. Modern web browsers (and Node.js) expose internationalization and time zone support via the Intl object, codified as ECMA-402. If one needs internationalization or time zone support, Moment can get quite large. Moment doesn't work well with modern "tree shaking" algorithms, so it tends to increase the size of web application bundles. Since this has already been accomplished in other libraries, we feel that it is more important to retain the mutable API.Īnother common argument against using Moment in modern applications is its size. We address it in our usage guidance but it still comes as a surprise to most new users.Ĭhanging Moment to be immutable would be a breaking change for every one of the projects that use it.Ĭreating a "Moment v3" that was immutable would be a tremendous undertaking and would make Moment a different library entirely. This is a common source of complaints about Moment. Given how many projects depend on it, we choose to prioritize stability over new features.Īs an example, consider that Moment objects are mutable. Moment has evolved somewhat over the years, but it has essentially the same design as it did when it was created in 2011. The modern web looks much different these days. And while we’re at it, we can install the react-moment package as well, which we’ll discuss has been successfully used in millions of projects, and we are happy to have contributed to making date and time better on the web.Īs of September 2020, Moment gets over 12 million downloads per week! However, Moment was built for the previous era of the JavaScript ecosystem. How to Use Moment.js With Reactīecause Moment.js is an external library, we must install it in our project folder. Those concerned about the long-term future of their app might want to consider other JavaScript date libraries. If you’re used to Moment and want to use it for your React app, you’re free to do so. However, the creators decided to stop releasing new versions. It’s still stable, and all methods work like they’re supposed to. ![]() So it can solve our internationalization problems easily.Īt this moment, the library is in maintenance mode. The Moment library is easy to learn and, as a bonus, supports many languages. This way, we don’t have to interact with the original Date API or change it. The library provides an API that wraps around the native Date object in JavaScript. It is also compatible with many popular JavaScript libraries, including React and TypeScript. It can be used for front-end applications as well as for server-side programming. It works with both - Node.js and regular JavaScript. Moment library is mainly used for parsing and formatting data values, but it has many features that may be useful for building modern apps.įor instance, Moment is useful for data validation as well. ![]() It is one of the most stable libraries for formatting dates in JavaScript. These allow us to work with dates much more efficiently, without wasting time and energy. Date API is insufficient for formatting, internationalizing, and in general, manipulating the dates.įor this reason, the community of JavaScript developers has created many date libraries to perform some of the more advanced operations. However, working with the Date object is easier said than done. ![]() Because of this fact, JavaScript includes a Date object, which is useful for simple operations involving date and time. Managing date and time is at the heart of building dynamic applications in React. React applications are not the exception to the rule. It’s hard to think of any modern web application involving dates and times.
0 Comments
Leave a Reply. |