javascript - 如何在反应日历中设置点击日期?
问题描述
我正在使用 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}
/>
);
解决方案
尝试更改为:
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
属性。
推荐阅读
- photo - iOS 14:使用新的“选定照片...”权限创建相册?并为专辑获取 AssetCollection?
- python - 将用户输入更改为列表中的 int 的更快方法?
- python - 将 Odoo 13 模块升级到 Odoo 14 时出现 Odoo 服务器错误
- php - 在 MySQL 数据库上查询使用 bcrypt 散列的字符串
- spring-boot - Spring data jpa CRUDRepository/ JPArepository saveall 无法获取id(非主键)
- angular - 未捕获(承诺):TypeError:无法读取未定义的属性“长度”
- python - 尝试安装 face_recognition 模块时出现 pip install 错误
- shell - 我可以向 Elixir 中的系统寻呼机发送一个字符串吗?
- c# - Autofac 6 - 根据其他服务的可用性注册装饰器
- c# - 如何在 Asp.Net Core 中使用 MailKit 发送电子邮件