We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4d3bb1c commit 2a7516fCopy full SHA for 2a7516f
src/useDataApiHook-example/index.js
@@ -39,19 +39,29 @@ const useDataApi = (initialUrl, initialData) => {
39
});
40
41
useEffect(() => {
42
+ let didCancel = false;
43
+
44
const fetchData = async () => {
45
dispatch({ type: 'FETCH_INIT' });
46
47
try {
48
const result = await axios(url);
49
- dispatch({ type: 'FETCH_SUCCESS', payload: result.data });
50
+ if (!didCancel) {
51
+ dispatch({ type: 'FETCH_SUCCESS', payload: result.data });
52
+ }
53
} catch (error) {
- dispatch({ type: 'FETCH_FAILURE' });
54
55
+ dispatch({ type: 'FETCH_FAILURE' });
56
57
}
58
};
59
60
fetchData();
61
62
+ return () => {
63
+ didCancel = true;
64
+ };
65
}, [url]);
66
67
const doGet = (event, url) => {
0 commit comments