目前在react中验证Date道具的首选方法是什么?

现在我正在使用:React.PropTypes.object

然而,这是现在失败的禁止-prop-types lint规则。我应该用一个形状还是有更好的方法?


当前回答

这对我很有效

PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.number,
    PropTypes.instanceOf(Date),
]).isRequired

其他回答

很确定你可以使用proptypes。instanceof (Date)

这对我很有效

PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.number,
    PropTypes.instanceOf(Date),
]).isRequired