我正在使用react-calendar,并试图在点击后设置特定日期的样式,但我只能找到如何设置整个月的样式。我试着研究是否可以包装一个在div中单击的日期,并将该div分配给一个类,但我找不到这样做的方法。还有其他想法吗?
export const CalendarPage = () => {
const datesToAddClassTo = ["Thu May 06 2021 00:00:00 GMT-0400 (Eastern Daylight Time)"];
function tileClassName({date, view) {
// Check if a date React-Calendar wants to check is on the list of dates to add class to
if (view === 'month') {
if (datesToAddClassTo[0] === date.toString()) {
console.log("Match found!!!!!");
return 'myClassName';
}
}
}
const [value, setValue] = useState(new Date());
function onChange(nextValue) {
setValue(nextValue);
}
return (
<Calendar
onChange={onChange}
value={value}
tileClassName={tileClassName}
/>
);发布于 2021-05-08 16:41:38
尝试将其更改为:
function tileClassName(data) {
const { _, date, view } = data;
// Check if a date React-Calendar wants to check is on the list of dates to add class to
if (view === 'month') {
if (datesToAddClassTo[0] === date.toString()) {
console.log("Match found!!!!!");
return 'myClassName';
}
}
}然后为.myClassName添加样式,如果它不适用-添加!important属性。
https://stackoverflow.com/questions/67444142
复制相似问题