反应大日历重复日期
react big calendar repeated date
我正在为一个应用程序使用 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
组件上。这个 worked fine for me. 在 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>
);
}
我正在为一个应用程序使用 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
组件上。这个 worked fine for me. 在 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>
);
}