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});
}

Related Query

More Query from same tag