Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cancelToken #2

Closed
stereobooster opened this issue Aug 26, 2017 · 1 comment
Closed

Add cancelToken #2

stereobooster opened this issue Aug 26, 2017 · 1 comment

Comments

@stereobooster
Copy link

Example code (facebook/react#8883 (comment)):

  fetchRepos() {
    // cancel the previous request
    if (this.source) {
      this.source.cancel('Operation canceled due to new request.')
    }

    // save the new request for cancellation
    this.source = axios.CancelToken.source();

    this.setState({networkState: 'loading' })

    let url = `https://api.github.com/users/${this.props.username}/repos`
    axios.get(url, { cancelToken: this.source.token })
      .then(response => this.setState({ repos: response.data, networkState: 'loaded' } ))
      .catch(error => {
        if (axios.isCancel(error)) {
          this.setState({ networkState: 'canceled' })
        } else {
          this.setState({ networkState: 'errored' })
        }
     });
  }
@miguelcaravantes
Copy link

can we reopen this? there is not cancelToken parameter yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants