Is this the correct way to define an array proptype of 2 moment instances?
Pacheco95 opened this issue · 3 comments
I need to define a PropType for a date range prop like:
[moment(), moment()]
Is this correct? Is there a better way?
DatePricker.propTypes = {
createdAt: PropTypes.arrayOf(PropTypes.instanceOf(moment)),
};
I tested passing an array with two normal javascrip dates and console log this
Warning: Failed prop type: Invalid prop `coupon.createdAt[0]` of type `Date` supplied to `CouponsFilter`, expected instance of `hooks`.
Can I replace this error message to ends with expected instance of 'moment'
?
hooks
is presumably the name of the moment
function (moment.name
?) otherwise i'm not sure where that name would come from.
This package's propTypes don't provide the ability to customize the message; you may want to check out https://npmjs.com/airbnb-prop-types for that.
Thank you for your response. I will check it out!
What about these questions? "Is this correct? Is there a better way?". Can you help me with them?
It is correct, and there is no better way using the core prop-types package.