{"library":"react-moment-proptypes","title":"Moment.js Prop Types for React","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install react-moment-proptypes"],"cli":null},"imports":["import momentPropTypes from 'react-moment-proptypes';","import momentPropTypes from 'react-moment-proptypes'; momentPropTypes.momentObj","import momentPropTypes from 'react-moment-proptypes'; momentPropTypes.momentString"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import React from 'react';\nimport PropTypes from 'prop-types';\nimport moment from 'moment';\nimport momentPropTypes from 'react-moment-proptypes';\n\nclass TestComponent extends React.Component {\n  render() {\n    return (\n      <div>\n        <p>Date Prop: {this.props.dateThing?.format('YYYY-MM-DD')}</p>\n        <p>UTC Date Prop: {this.props.dateThingWithPredicate?.format('YYYY-MM-DD HH:mm [UTC]')}</p>\n        <p>String Date Prop: {this.props.stringThing}</p>\n        <p>Duration Prop: {this.props.durationThing?.humanize()}</p>\n      </div>\n    );\n  }\n}\n\nTestComponent.propTypes = {\n  dateThing: momentPropTypes.momentObj,\n  dateThingWithPredicate: momentPropTypes.momentObj.withPredicate(\n    function isUTC(momentObject) {\n      return momentObject.isUTC();\n    }\n  ),\n  stringThing: momentPropTypes.momentString,\n  durationThing: momentPropTypes.momentDurationObj\n};\n\n// Example Usage\nconst App = () => (\n  <TestComponent\n    dateThing={moment()}\n    dateThingWithPredicate={moment.utc()}\n    stringThing={'12-12-2014'}\n    durationThing={moment.duration(3, 'hours')}\n  />\n);\n\nexport default App;","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}