Created
March 2, 2020 11:04
-
-
Save jwchang0206/542f3258fca9a58e19d76602f98f1f68 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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