Does anyone know how I can pass an array of dates to react-datetime? I'm trying to implement a datepicker which can display "booked" dates from my state but currently I only managed to disable all days before the current one. So how can I pass the dates in my state to <Datetime/>
, in order to disable them?
'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;