use-hooks/react-hooks-axios

Cancel Request.

apenab opened this issue · 3 comments

Hi, good work guys.
I think about the implementation of canceling the request when the component is unmounted, cancel the previous request and add a type of debounce.
What do you think about this?

Good propose!

After reading the doc, it looks ok.

If this is to avoid calling setState on unmounted component, this might be simpler.

React.useEffect(() => {
  let didCancel = false;
 
  // ...
  // you can check didCancel
  // before running any setState
  // ...
 
  return () => {
    didCancel = true;
  };
});

Was recommended in discussion here: facebook/react#14369

Via 1.1.1