reactjs - 反应大日历重复日期
问题描述
我正在将 react-big-calendar 用于应用程序,但是当我迈出第一步时,我意识到出了点问题......每月有两天重复,目前 2021 年 3 月的星期六和星期日都有 13 日
你能给我一个关于如何解决这个问题的提示吗?一切都很好,除了
谢谢
import { Calendar, momentLocalizer } from 'react-big-calendar'
import moment from 'moment'
import 'react-big-calendar/lib/css/react-big-calendar.css'
const localizer = momentLocalizer(moment)
const event = [{
start: moment().toDate(),
end: moment().add(2, 'hours').toDate(),
title: 'Cumple'
}]
export const CalendarScreen = () => {
return (
<div>
<Calendar
events={event}
startAccessor="start"
endAccessor="end"
style={{ height: '100vh' }}
/>
</div>
)
}
解决方案
我认为那是因为您没有将localizer
道具放在Calendar
组件上。这对我来说很好。在 CodeSandbox 中。
import { Calendar, momentLocalizer } from "react-big-calendar";
import moment from "moment";
import "react-big-calendar/lib/css/react-big-calendar.css";
const localizer = momentLocalizer(moment);
const event = [
{
start: moment('2021-03-14', 'YYYY-MM-DD').toDate(),
end: moment('2021-03-14', 'YYYY-MM-DD').add(2, "hours").toDate(),
title: "Cumple"
}
];
export default function CalendarScreen() {
// You must set explicit height on your container
// I used `defaultDate` to target test the specific
// date, which is DST where I am, so you see 3AM twice
// in the TimeGrid (Day/Week views).
return (
<div style={{ position: "relative", height: 950 }}>
<Calendar
localizer={localizer}
events={event}
startAccessor="start"
endAccessor="end"
defaultDate={new Date(2021, 2, 14)}
/>
</div>
);
}
推荐阅读
- python - 如何根据流行的字符串和簇创建新列?
- javascript - 挣扎于页脚和模式
- vba - 如何将用户表单列表框中的选择填充到项目符号 MS-Word-VBA 中?
- postgresql - 在 PostgreSQL 中解析文本数据
- google-pay - 在谷歌支付(谷歌钱包)中存储二维码
- python - 如何将 Django env 文件夹添加到 .gitignore?
- javascript - 使用 Express Backend 动态更改 React Js 应用程序的元标记
- python - 检查与 AST 参数规范的兼容性
- android - 使用材料设计为 androidx.legacy:legacy-support-v4:1.0.0 更改 androidx.appcompat.widget.SearchView(操作栏中的搜索图标)
- python - 类型错误:+ 不支持的操作数类型:“datetime.datetime”和“datetime.time”