score:39
Accepted answer
this was my solution :)
var numberofajaxcallpending = 0;
// add a request interceptor
axios.interceptors.request.use(function (config) {
numberofajaxcallpending++;
// show loader
return config;
}, function (error) {
return promise.reject(error);
});
// add a response interceptor
axios.interceptors.response.use(function (response) {
numberofajaxcallpending--;
console.log("------------ ajax pending", numberofajaxcallpending);
if (numberofajaxcallpending == 0) {
//hide loader
}
return response;
}, function (error) {
numberofajaxcallpending--;
if (numberofajaxcallpending == 0) {
//hide loader
}
return promise.reject(error);
});
Source: stackoverflow.com
Related Query
- Know if there are pending request in axios
- Is there a way to know in the parent block that you are editing an inner block of that parent?
- how to send only one value of mail to backend if there are multiple inputs to axios post
- How to know which button is clicked when there are multiple buttons (React)
- Axios post request parameters to backend are undefined
- Axios Post request for login is showing pending status?
- Why is my axios post request not sending data? I'm getting a response that means the fields are empty
- Axios and fetch both in Reactjs are making continuous localhost network request
- Axios 'GET' request is pending but it never reaches the server
- Is there something missing in this code ? I am unable to post through axios post request
- axios post request to send form data
- Axios Delete request with body and headers?
- how to cancel/abort ajax request in axios
- How do I create configuration for axios for default request headers in every http call?
- Make request to SOAP endpoint using axios
- GraphQL post request in axios
- body data not sent in axios request
- Default query params not getting passed in axios request
- How to show progress of Axios during get request (not download or upload)
- axios post request with json data
- Is there a way to set global axios config for error response codes
- What are the differences between Redux-Thunk and Redux-Promise when used with Axios apis?
- React.js Decorators are not supported yet in 6.x pending proposal update
- React Axios - C# WebAPI request token fails without a server error
- React: Are there respectable limits to number of props on react components
- Making redirects after an axios post request with express
- Are there alternative libraries for Relay and GraphQL?
- Cancel axios get request when typing reactjs
- Error: Request failed with status code 401 axios in React JS
- Getting 400 error Bad request using axios
More Query from same tag
- React.js class programming not able to stop count down timer
- Uncaught TypeError: Super expression must either be null or a function
- React child component not fetching props and updating state
- FlatList calling twice
- How do I declare a generic React component in a const variable from a higher-order component?
- Combine 2 objects and maintain order
- Graphene mutation defined as null despite returned value is NonNull
- How to transpile node_modules folder using just babel 7?
- simple react-pose opacity transition dont work
- using react hooks displaying data in the browser
- Change nav-link style depending on which div is in viewport in React
- Can you use normal CSS with React?
- Can't get my form in React to work properly
- (crl + /) in vscode short cut makes incorrect jsx comment
- Webpack successfully builds, but JavaScript doesn't execute runtime
- Server side rendering React components that loads state through Ajax
- How do we break HTML semantics by using <div> in ReactJs (Jsx)
- How do I pass my API data to a React component? (Sandbox link included)
- How do I interact with the useState in this UserContext?
- How to resolve "Uncaught TypeError: Failed to construct 'Comment': Please use the 'new' operat....." with respect to React JS?
- 'Eperm: operation not permitted' when using multer
- Handle mulitple checkboxes in React
- How can I import uploadcare into a react.js project?
- Cannot authenticate with Graph API access token on proprietary API
- Default props in theme configuration seems not to work
- Call event outside of function
- Formik adds new Array of value instead of adding only the value
- Return multiple values for antd form item, value pass in array of items
- Reading array values inside jsx
- Doing custom hover animation on nav items(bootstrap nav) but the effect isn't visible in my react application