Issue with loading function in FullCalendar React integration

Currently experimenting with FullCalendar v5 for React and exploring the Resource Timeline view feature. Facing an issue with the "loading" function - the idea is to monitor the state of FullCalendar and, if it's in a loading state, display a Spinner component instead of the Timeline. The plan was to trigger the Spinner component by changing its state using useState within the FullCalendar component itself, which resulted in an infinite render loop. Any suggestions on how to resolve this?

 
// Implementation of loading function and useState method in the container component of FullCalendar

const [spinner, setSpinner] = useState(true);

let loadingFunction = (isLoading) => {
  if (isLoading) {
    console.log("loading");
    setSpinner(true);
  } else {
    console.log("idle");
    setSpinner(false);
  }
};

// Conditional rendering logic
return (
  <>
    {spinner ? (
      <Spinner />
    ) : (
      <>
        <FullCalendar
          loading={loadingFunction}
          ref={calendarRef}
          dateClick={handleEventCreate}
          .....
          

Answer №1

Entered into the same scenario. My method, perhaps a bit unconventional, goes like this. Rather than using a state variable to control the spinner's display, I decided to incorporate a CSS class that hides it off screen. I then obtained a reference to the spinner and, during the loading process in FullCalendar, I executed a function that removed the off-screen class temporarily, only to add it back once the loading was completed.

    /**
    * @type {{current: HTMLElement}}
    */
    const ripple = useRef(null);

    const toggleSpinner = useCallback((state) => {
        if (ripple.current) {
            if (state) {
                ripple.current.classList.remove("off-screen");
            }
            else {
                ripple.current.classList.add("off-screen");
            }
        }
    }, [ripple]);

    /*...*/

    return <>
        <div ref={ripple} className="off-screen spinner"></div>
        <FullCalendar
            loading={s => toggleSpinner(s)}

        />

    </>

Wishing you success, Staffan

Answer №2

It appears that the issue extends beyond a simple conditional display of the calendar.

Consider this code snippet:

  const [loading, setLoading] = useState(false)
  ...

  {loading ? <Spinner /> : null}

  <FullCalendar
    plugins={[ dayGridPlugin ]}
    initialView="dayGridMonth"
    loading={e => setLoading(e)} // This line seems to cause an infinite loop when loading
    eventSources={[{
        url: '/api/calendar',
        method: 'GET',
      }]}
    />

The calendar works fine without the loading line, but adding it results in continuous reloads and a spinning loader during data fetches.

Any change triggers a reload of the data source, leading to this unexpected behavior.

This could be a bug or lack of clarity in the documentation for FullCalendar in React (https://fullcalendar.io/docs/loading).

It's worth noting that this issue does not occur with just initialEvents, although that option limits flexibility.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The calculator I designed using HTML, CSS, and JavaScript is experiencing difficulty adjusting to various screen sizes

I recently built a calculator using HTML, CSS, and JavaScript. It works perfectly on PC or big screens, but when viewed on smaller devices like phones or tablets, the display gets cut off and does not adjust properly. Here are some example pictures for ref ...

React application experiencing incorrect hexadecimal hash value output in crypto function

In my Reactjs app rendered by Nextjs, I am confused about why I am receiving different hash values in the web browser when using this code: crypto.createHash('sha256').update("12345678").digest("hex"); The expected hash value from the sha256 on ...

Nested divs with independent scrolling capabilities

I am interested in developing a gantt chart that displays days, months, and years at the top with tasks listed below. Here is my progress so far: https://i.stack.imgur.com/tr5y4.png In the image above, the scroll-x functionality works on everything incl ...

Display excerpts of code within an Angular application within the HTML segment

I'm currently developing a tutorial page using Angular where I intend to display code snippets in various programming languages such as 'Java', 'TypeScript', 'C#', and 'Html'. Although there is a snippet called ...

Positioning a centered div with absolute positioning may result in offset issues on Android devices when the content exceeds the viewport size

Encountering a peculiar issue on Android browsers, particularly when the following elements are present on a page: A div element larger than the device's viewport size. (In this case, set at 1200px.) One or more other div elements styled for centeri ...

Using Material UI Tooltip for displaying multi-line content on a web page

Currently, I'm utilizing Material UI for my React Components. Take a look at the code snippet below to see how I am linking the Tooltip title attribute. <Tooltip disableFocusListener title={xyzStore.mytestMultiLineContent} > <span> ...

What's the best way to establish the namespace for styled components within a create-react-app environment?

As I work on my react app using create-react-app, I am determined to find a way to customize the generation of classes without needing to eject the webpack config. To achieve this, I have turned to using react-app-rewired along with react-app-rewire-styled ...

The sticky positioning feature seems to be malfunctioning exclusively on mobile devices

I have encountered an unusual issue while working on my cafe-shop menu. Despite finding a solution in a standalone HTML file, the menu doesn't function properly when inserted into one of the pages of my WordPress theme - specifically, it only works on ...

After successfully deploying on Netlify, ReactDOM.createRoot() does not insert the #root div

Currently experiencing an issue while attempting to deploy a React application on Netlify. The app functions correctly in the local environment, and the deployment process completes without errors. However, upon previewing the site, the <App> compone ...

How to increase the width of the bars in an Apex chart's pie chart

Is there a way to increase the thickness of the bar? import React from "react"; import Chart from "react-apexcharts"; const series = [44, 55, 41, 17, 15]; const options = { chart: { type: "donut" } }; export default f ...

Tips for compiling JSX files for React in Rails 7

In my current project, I have a React component located at javascript/application/components/star_rating.js.jsx. Now, I am trying to implement this component in another part of my JS code with the following snippet: let starRating = <StarRating name={na ...

Is it possible to display one division on top of another with a transparent opacity effect in HTML?

I'm struggling with designing web pages and currently working on a page on codepen.io using code from this link. <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1 ...

How about a material-ui card housing an interactive openlayers map?

I'm struggling to insert an openlayers map into a material-ui card component. I've experimented with placing a div containing the map within both the card text and media sections. Could someone assist me in determining the correct method for emb ...

Cut off a string from the start

I'm using the text-overflow: ellipsis property in a div to shorten lengthy text values. Since there is no white space in the URL, I want to prevent the overflow from increasing the width of the div. What I want to achieve is to display the following: ...

Does the entire state get replaced every time a change is made if the state is immutable?

Is it necessary to replace the entire state if it is immutable? Otherwise, wouldn't mutating the state occur? Are top-level keys maintained as distinct immutable objects? Wouldn't changing anything necessitate replacing the entire state by defin ...

jQuery Ajax form submission encountering issues

I created a form dynamically with the help of jQuery. Here is the code: <form id="editorform" accept-charset="utf-8" method="post" name="editorform" action="menuupdate"> <div> <input id="updateItem" type="submit" value="Update"& ...

An error occurs when trying to execute the "products" function after performing destruct

I designed my homepage to showcase the products using the redux method. However, I did not want to display them all on the home page at once, so I created a single product component instead. But then I decided I wanted to show the products in a carousel us ...

Styles for Material UI 5 class names

After upgrading from Mui 4 to 5, I am facing a challenge in using class names effectively. While the SX property allows me to apply styles to individual components, I am struggling with applying the same class to multiple components. In version 4, my code ...

Contenteditable feature dynamically styling text upon input

Is it possible to prevent CSS properties like text-transform from affecting text entered via contenteditable? On my webpage, "CERTIFICATE PROGRAM" is shown in uppercase due to text-transform settings. However, the original input was: Certificate Program. ...

Bootstrap CDN causing modals to fail to appear

Here are the stylesheets I am currently using: script(src="/js/application.js") script(src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js") script(src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js") link(rel="styl ...