score:2
you have to store your requests somewhere and to abandon old ones by making only one request active. something like:
getdata = async function() {
console.log(this.state.active);
this.setstate({ data: [] });
// my code starts here
if (this.controller) { controller.abort() }
this.controller = new abortcontroller();
var signal = controller.signal;
let resp = await fetch(`https://swapi.co/api/${this.state.active}/`, { signal });
let data = await resp.json();
let results = data.results;
if(data.next !== null) {
do {
let nextresp = await fetch(data.next);
data = await nextresp.json();
let nextresults = data.results
results.push(nextresults);
results = results.reduce(function (a, b) { return a.concat(b) }, []);
} while (data.next);
}
this.setstate({ data: results});
}
Source: stackoverflow.com
Related Query
- Handling multiple ajax requests, only do the last request
- AJAX > MongoDB query only works five times, then server stops handling requests, and I can't refresh the page
- Make Multiple Post Requests In Axios then get all the response to make another request
- reactjs handles only the last api request data
- React: useState hook updates only the last instance from multiple instances of the same functional component
- multiple react state updates renders only the last update
- How to wait for AJAX response and only after that render the component?
- How to avoid sending multiple duplicate AJAX requests in axios
- Why is componentDidMount the best place to fire AJAX request
- Why is only the last item in a map function being changed in react app?
- What is the best way to make multiple get request with axios in a loop?
- Redux Observable throttle Ajax requests only some conditions met
- Making 2 sequential requests with Axios - second request depends on the response of 1st
- Issuing AJAX request in the callback of setState()
- How to make AJAX GET request on the client to external site with React
- I wanted to save two values in this.props.onChange but only is saving the last
- Handling multiple instances of the same component in Flux
- AXIOS: how to run http requests concurrently and get the result of all requests event if a request fails
- Send multiple axios requests in a for loop in series (One after the other)
- React - what is the proper way to reload after multiple axios requests are done
- react.js typescript spread(...) adding only the last element
- How to make multiple HTTP requests with RxJS and merge the response into one payload and map it to another action?
- how to cancel the earlier fetch request and keep the last one during search
- When attempting to stub a request in Cypress IO (JS) against a React app using fetch, the requests still call through to the server
- Optimized way to toggle multiple divs with the same handling function in React
- onClick event only leaves the last item of the DOM array instead of removing the target
- React.JS - multiple elements sharing a state ( How do I modify only one of the elements without affecting the others? )
- When making multiple ajax requests, is there a "good pattern" for tracking which data the responses line up with?
- Render data from multiple ajax request
- Handling multiple ajax calls in react
More Query from same tag
- JSX dismiss an arrow (>) in HTML
- React + Webpack: Where to configure REST Endpoints
- Typescript array of objects as props
- What's the best practice for making an optionally editable text field in react?
- react bootstrap carousel Items "Each child in a list should have a unique "key" prop"
- Transform Function Component to a Class Component
- React redux -- input field not letting me type
- I want to upload a image and add URL of the image to firestore
- TypeError: JSON.stringify(...).then is not a function - React JS
- Not able to read the json body response from aws lambda (java). It says ReadableStream
- Not able to fetch data from node.js API hosted on localhost using ReactJs
- Add new items to my shopping cart in React
- How do I clear the React Root Window programatically?
- Communication between Django and React
- TypeScript: Why is Parameters generic accepting incorrect arguments?
- useEffect stops working after the first time useState's set becomes stale within a timer
- NextJS tracking scroll position. window.ScrollY always equals 0
- How to disable redux devtool to hide state in browser after production?
- How to communicate between Mobx stores created with React.createContext
- how to get info about page loading from server
- Redux thunk function not running
- IntersectionObserverAPI Return to default state when none of the elements are visible
- How to go specific route without rendering some components in React?
- How to communicate between two components in Reactjs
- React Router cannot detect match props
- Add behaviour to a react-router Link
- href doesn't work, using react router
- Is there a way to pass an Apollo query selection through react props?
- React, CSS - Remove White Background at the end of the website in App.css
- Adyen's Checkout SDK integration in react app