Skip to content

Instantly share code, notes, and snippets.

@jwchang0206
Created March 2, 2020 11:04
Show Gist options
  • Save jwchang0206/542f3258fca9a58e19d76602f98f1f68 to your computer and use it in GitHub Desktop.
Save jwchang0206/542f3258fca9a58e19d76602f98f1f68 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
class Foo {
constructor(props) {
super(props);
this.tokens = [];
}
componentWillUnmount() {
// Cancel all the tokens generated within this component
this.tokens.forEach(token => {
token.abort();
});
}
makeRequest() {
const controller = new AbortController();
this.tokens.push(controller);
// Use this signal for Fetch
dispatch('ACTION_REQUEST', { signal: controller.signal });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment