axios-hooks
Advanced tools
Comparing version 1.10.1-3 to 1.10.1-4
@@ -5,2 +5,9 @@ # Changelog | ||
### [1.10.1-4](https://github.com/simoneb/axios-hooks/compare/v1.10.1-3...v1.10.1-4) (2020-06-20) | ||
### Bug Fixes | ||
* **250:** more robust cancellation approach ([e4f9189](https://github.com/simoneb/axios-hooks/commit/e4f91891f8b86edbc40f70fad57686d564956881)) | ||
### [1.10.1-3](https://github.com/simoneb/axios-hooks/compare/v1.10.1-2...v1.10.1-3) (2020-06-20) | ||
@@ -7,0 +14,0 @@ |
@@ -265,3 +265,3 @@ "use strict"; | ||
var cancelSourceRef = _react["default"].useRef(_axios["default"].CancelToken.source()); | ||
var cancelSourceRef = _react["default"].useRef(); | ||
@@ -278,8 +278,14 @@ var _React$useReducer = _react["default"].useReducer(reducer, createInitialState(options)), | ||
var cancelOutstandingRequest = _react["default"].useCallback(function () { | ||
if (cancelSourceRef.current) { | ||
cancelSourceRef.current.cancel(); | ||
} | ||
}, []); | ||
var withCancelToken = _react["default"].useCallback(function (config) { | ||
cancelSourceRef.current.cancel(); | ||
cancelOutstandingRequest(); | ||
cancelSourceRef.current = _axios["default"].CancelToken.source(); | ||
config.cancelToken = cancelSourceRef.current.token; | ||
return config; | ||
}, []); | ||
}, [cancelOutstandingRequest]); | ||
@@ -291,5 +297,3 @@ _react["default"].useEffect(function () { | ||
return function () { | ||
return cancelSourceRef.current.cancel(); | ||
}; // eslint-disable-next-line react-hooks/exhaustive-deps | ||
return cancelOutstandingRequest; // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [stringifiedConfig]); | ||
@@ -296,0 +300,0 @@ |
@@ -244,3 +244,3 @@ import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
}, options); | ||
var cancelSourceRef = React.useRef(StaticAxios.CancelToken.source()); | ||
var cancelSourceRef = React.useRef(); | ||
@@ -257,8 +257,13 @@ var _React$useReducer = React.useReducer(reducer, createInitialState(options)), | ||
var cancelOutstandingRequest = React.useCallback(function () { | ||
if (cancelSourceRef.current) { | ||
cancelSourceRef.current.cancel(); | ||
} | ||
}, []); | ||
var withCancelToken = React.useCallback(function (config) { | ||
cancelSourceRef.current.cancel(); | ||
cancelOutstandingRequest(); | ||
cancelSourceRef.current = StaticAxios.CancelToken.source(); | ||
config.cancelToken = cancelSourceRef.current.token; | ||
return config; | ||
}, []); | ||
}, [cancelOutstandingRequest]); | ||
React.useEffect(function () { | ||
@@ -269,5 +274,3 @@ if (!options.manual) { | ||
return function () { | ||
return cancelSourceRef.current.cancel(); | ||
}; // eslint-disable-next-line react-hooks/exhaustive-deps | ||
return cancelOutstandingRequest; // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [stringifiedConfig]); | ||
@@ -274,0 +277,0 @@ var refetch = React.useCallback(function (configOverride, options) { |
{ | ||
"name": "axios-hooks", | ||
"version": "1.10.1-3", | ||
"version": "1.10.1-4", | ||
"description": "axios-hooks", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -160,3 +160,3 @@ import React from 'react' | ||
const cancelSourceRef = React.useRef(StaticAxios.CancelToken.source()) | ||
const cancelSourceRef = React.useRef() | ||
@@ -174,11 +174,21 @@ const [state, dispatch] = React.useReducer( | ||
const withCancelToken = React.useCallback(config => { | ||
cancelSourceRef.current.cancel() | ||
cancelSourceRef.current = StaticAxios.CancelToken.source() | ||
const cancelOutstandingRequest = React.useCallback(() => { | ||
if (cancelSourceRef.current) { | ||
cancelSourceRef.current.cancel() | ||
} | ||
}, []) | ||
config.cancelToken = cancelSourceRef.current.token | ||
const withCancelToken = React.useCallback( | ||
config => { | ||
cancelOutstandingRequest() | ||
return config | ||
}, []) | ||
cancelSourceRef.current = StaticAxios.CancelToken.source() | ||
config.cancelToken = cancelSourceRef.current.token | ||
return config | ||
}, | ||
[cancelOutstandingRequest] | ||
) | ||
React.useEffect(() => { | ||
@@ -193,3 +203,3 @@ if (!options.manual) { | ||
return () => cancelSourceRef.current.cancel() | ||
return cancelOutstandingRequest | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
@@ -196,0 +206,0 @@ }, [stringifiedConfig]) |
46327
712