有谁知道我如何将一组日期传递给 react-datetime?我正在尝试实现一个日期选择器,它可以显示我所在州的“预订”日期,但目前我只设法禁用当前日期之前的所有日期。那么如何将我所在州的日期传递给<Datetime/>
,以禁用它们?
'use strict';
import React from 'react';
import {PropTypes} from 'prop-types';
import Datetime from 'react-datetime';
class DatePicker extends React.Component {
constructor(props) {
super(props);
this.state = {
dates: [{id: 1, date: 'Apr 30 2020 09:00:00 AM'}, {id: 2, date: 'May 1 2020 12:00:00 PM'}]
};
}
render() {
const {t} = this.props;
let yesterday = Datetime.moment().subtract(1, 'day');
let valid = function (current) {
return current.isAfter(yesterday);
};
return (
<div className="date-picker">
<p>{t('Date Picker')}</p>
<Datetime timeFormat={false} isValidDate={valid(yesterday)}/>
</div>
);
}
}
export default DatePicker;