react-moment is a React component that acts as a wrapper for the widely-used `moment.js` date and time library. It enables developers to easily display formatted dates and times within React applications, leveraging Moment's extensive parsing, formatting, and manipulation capabilities. The current stable version, 1.2.2, integrates with `moment.js` versions 2.29.0 and higher. While `moment.js` itself is now considered a legacy project with its maintainers recommending modern alternatives like Luxon, date-fns, or Day.js, `react-moment` remains functional for projects still relying on the Moment.js ecosystem. It provides a declarative, component-based API for Moment's features, including relative time ("from now"), calendrical formatting, and custom date displays, often with built-in interval updates. The library also ships with TypeScript types, enhancing the developer experience in typed React projects.
npm install react-momentVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of the `Moment` component for various date and time displays, including custom formatting, relative time with live updates, and calendar views.
For new development, consider adopting a modern date library and its corresponding React component (e.g., `react-day-picker`, `react-date-fns`). If maintaining an existing project with `react-moment`, be aware of `moment.js`'s maintenance-only status and potential implications for long-term support and bundle size.
Install `moment-timezone` via `npm install --save moment-timezone` and then include `import 'moment-timezone';` in your application's entry point or the component where timezone functionality is utilized.
To update more frequently (e.g., every second for a live clock), explicitly set a lower `interval` value, such as `interval={1000}`. Set `interval={0}` to disable automatic updates entirely.If bundle size is a critical concern, re-evaluate the need for `moment.js` and consider migrating to lighter alternatives. If `moment.js` is essential, ensure you are only importing necessary locales or specific timezone data if not using the full `moment-timezone` package.
Ensure `prop-types` is installed in your project: `npm install prop-types`.
Install `moment` by running: `npm install --save moment react-moment`.
Install `moment-timezone`: `npm install --save moment-timezone`, and then add `import 'moment-timezone';` to your application's main entry file or the relevant component.
Change your import statement from `import { Moment } from 'react-moment';` to `import Moment from 'react-moment';`.Ensure the `Moment` component receives a valid date value: `<Moment date={myDateVar} />` or `<Moment>{myDateVar}</Moment>`.