DEV Community

kngo73
kngo73

Posted on

How to stop repeated Ajax calls in React class ?

Hello, I inherited an old version of React that starts like this:

var rc = React.createClass({

 render() {

      // Ajax code, here, is called repeatedly for some reason

      return {
           ...
      }
 }
Enter fullscreen mode Exit fullscreen mode

})

I'm stuck with this old code architecture, and I could not import React component. I tried to make an Ajax call to the server side using jQuery and saw the expected result returned in the console. I also tried using React to make the Ajax call but no result was returned, perhaps due to the lack of the React Component.

The problem is that, for whatever reason, the Ajax was called repeatedly, non-stop, for both React & jQuery methods (the Ajax code was not inside any loop). I didn't have this Ajax repeating issue at home when I used a more recent version of React. At work, I had to work with the above code implemented by a previous developer. I have tried all possible solutions to stop / abort the Ajax after the first call but not successful. Any idea ? Thanks a lot!

Top comments (0)