我想突出显示特定日期范围(选定日期后 6 天)。我试过这个。但不工作。解决方案是什么?这是我参考的示例代码
import React from "react";
import moment from 'moment';
import DayPicker, { DateUtils } from "react-day-picker";
import "react-day-picker/lib/style.css";
export default class DisabledDays extends React.Component {
state = {
from: null,
to:null,
};
handleDayClick(e, day, modifiers) {
const range = DateUtils.addDayToRange(day, this.state);
this.setState(range);
}
handleChange = (day) => {
console.log("newDate", day);
return this.setState({date: day});
}
render() {
const { from, to} = this.state;
// Add the `selected` modifier to the cell of the clicked day
const modifiers = {
//disabled: DateUtils.isPastDay,
//selected: day => DateUtils.isSameDay(this.state.from, day),
selected:day => DateUtils.isDayInRange(day, this.state)
};
return <DayPicker selected={this.state.startDate} enableOutsideDays modifiers={ modifiers } onDayClick={ this.handleChange } minDate={moment()} maxDate={moment().add(5, 'days')}
placeholderText="Select a date between today and 5 days in the future" />;
}
}