FullCalendar is not updating after React state change
See original GitHub issueI am using FullReact calendar (https://fullcalendar.io/docs/react) in my own wrapper component (Calendar):
const Calendar = (props) => {
const [isMonthlyViewEnabled, setIsMonthlyViewEnabled] = useState(true);
return (
<Card fluid>
<Card.Content>
<FullCalendar
defaultView={isMonthlyViewEnabled ? "dayGridMonth" : "timeGridWeek"}
plugins={[dayGridPlugin, timeGridPlugin]}
events={props.events}
/>
</Card.Content>
<Card.Content extra>
<Button primary>Add Appointment</Button>
<Button color={'green'} onClick={() => setIsMonthlyViewEnabled(!isMonthlyViewEnabled)}>
Switch to {isMonthlyViewEnabled ? "weekly" : "monthly"} view
</Button>
</Card.Content>
</Card>
);
};
Initially, the button will display the text: ‘Switch to weekly view’. Upon click, it will flip isMonthlyViewEnabled and switch the name of the button to ‘Switch to monthly view’ and the defaultView of FullCalendar to “timeGridWeek”.
However, when I click the button, the button text is changing as expected (so I know the state is working correctly), but the FullCalendar default view is not changing. Does anyone know how I can make the FullCalendar component rerender with the proper defaultView?
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
FullCalendar is not updating after React state change #7075
I am using FullReact calendar (https://fullcalendar.io/docs/react) in my own wrapper component (Calendar):. const Calendar = (props) => { const ...
Read more >FullCalendar is not updating after React state change - Reddit
I am using FullReact calendar ( https://fullcalendar.io/docs/react ) in my own wrapper component (Calendar): const Calendar = (props) ...
Read more >Fullcalendar re-fetch events after change in React state
I believe this happens because every render is processes "events={getCalendarEvents(calendarId)}", which creates new reference to function.
Read more >Fullcalendar re-fetch events after change in React state-Reactjs
Coding example for the question Fullcalendar re-fetch events after change in React state-Reactjs.
Read more >@fullcalendar/react - npm
The official React Component for FullCalendar. Latest version: 6.0.1, last published: 5 days ago. Start using @fullcalendar/react in your ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Basically you can use asynchronous function and re-render FullCalendar component. For example if you want to add new event locally:
in the example above, I wanted to show changing state does not re-render the calendar so I disabled built-in buttons to make it more clear in my real use case, header is different so I prefer to implement it myself to have full control over it instead of dealing with customization. I know I can change view using API via refs (which I already do in my project) but I expected FullCalendar re-render on prop changes (which still makes sense)
and by the way, lemme thank you for this great work, it saves days for devs