react-moment-proptypes provides custom React PropTypes for validating `moment` objects, `moment` duration objects, and strings that `moment` can parse into valid dates. It ensures that React components receive expected date/time formats, leveraging the `moment.js` library. The current stable version is 1.8.1. Releases appear to be driven by dependency updates and bug fixes rather than a strict schedule, with recent activity focusing on modernizing development dependencies and addressing compatibility issues. It is a utility layer bridging React's prop-type validation system with Moment.js's data structures, allowing developers to define robust type checks for time-related props without manual validation logic.
npm install react-moment-proptypesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define and use `react-moment-proptypes` within a React component. It showcases `momentObj` for Moment objects, `momentString` for date strings, and `momentDurationObj` for Moment durations, including using `withPredicate` for custom validation.
If your application relies on custom `moment.createFromInputFallback` behavior, ensure it is defined globally or within your application logic, outside of `react-moment-proptypes`.
Upgrade your Node.js environment to version 8.x or newer to ensure compatibility and receive security updates for development dependencies.
Refer to the Moment.js documentation on warnings (http://momentjs.com/guides/#/warnings/js-date/) and ensure that strings passed to `momentString` props conform to recognized formats or handle `createFromInputFallback` appropriately.
Always use `package-lock.json` or `yarn.lock` in your *application* projects to ensure reproducible builds, regardless of whether a library provides its own lock file.
Ensure that string date inputs are in a clearly defined, standard format (e.g., ISO 8601 'YYYY-MM-DDTHH:mm:ssZ'). For custom formats, consider defining a `moment.createFromInputFallback` function or explicitly specifying the format when creating moment objects.
Verify your import statement: `import momentPropTypes from 'react-moment-proptypes';` for ESM or `const momentPropTypes = require('react-moment-proptypes');` for CommonJS. Ensure `react-moment-proptypes` is correctly installed in `node_modules`.