【发布时间】:2021-06-18 01:03:17
【问题描述】:
我正在使用 FullCalendar 进行反应,我正在努力应对状态....它返回此消息:
错误:超过最大更新深度。当组件在 componentWillUpdate 或 componentDidUpdate 中重复调用 setState 时,可能会发生这种情况。 React 限制了嵌套更新的数量以防止无限循环。
我删除了代码中所有不必要的部分。
import React, { useState, useEffect } from "react";
import FullCalendar from "@fullcalendar/react";
import dayGridPlugin from "@fullcalendar/daygrid";
const Top = () => {
// Calendar info stored in state
const [calendarEvents, setCalendarEvents] = useState([]);
// method to retrieve dates
const getEventsForThisMonth = () => {
const events = [];
events.push({
title: "test",
date: '2021-03-25',
});
return events;
};
useEffect(() => {
const eventsCollected = getEventsForThisMonth();
setCalendarEvents(eventsCollected);
}, [calendarEvents]);
return (
<>
<FullCalendar
defaultView="dayGridMonth"
plugins={[dayGridPlugin]}
events={calendarEvents}
locale="ja"
/>
</>
);
};
export default Top;
如果您希望我提供更多信息,请告诉我。 欢迎任何反馈/想法! 谢谢
【问题讨论】:
标签: reactjs fullcalendar gatsby