Created
March 2, 2020 11:04
-
-
Save jwchang0206/542f3258fca9a58e19d76602f98f1f68 to your computer and use it in GitHub Desktop.
Revisions
-
jwchang0206 created this gist
Mar 2, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ 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 }); } }