Skip to content

Commit

Permalink
fix: use StaticAxios for cancellation as AxiosInstance doesn't expose it
Browse files Browse the repository at this point in the history
fix #80
  • Loading branch information
simoneb committed Nov 13, 2019
1 parent cd60ec6 commit 4a63b6e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import DefaultAxios from 'axios'
import StaticAxios from 'axios'
import LRU from 'lru-cache'

const actions = {
Expand All @@ -14,7 +14,7 @@ let axiosInstance

export function resetConfigure() {
cache = new LRU()
axiosInstance = DefaultAxios
axiosInstance = StaticAxios
}

resetConfigure()
Expand Down Expand Up @@ -97,7 +97,7 @@ async function request(config, dispatch) {
dispatch({ type: actions.REQUEST_END, payload: response })
return response
} catch (err) {
if (axiosInstance.isCancel(err)) {
if (StaticAxios.isCancel(err)) {
return
}

Expand Down Expand Up @@ -145,7 +145,7 @@ export default function useAxios(config, options) {
}

React.useEffect(() => {
cancelSourceRef.current = axiosInstance.CancelToken.source()
cancelSourceRef.current = StaticAxios.CancelToken.source()

if (!options.manual) {
executeRequest(
Expand Down
2 changes: 0 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,6 @@ describe('configure', () => {
it('should provide a custom implementation of axios', () => {
const mockAxios = jest.fn().mockReturnValueOnce({ data: 'whatever' })

mockCancelToken(mockAxios)

configure({ axios: mockAxios })

const { waitForNextUpdate } = renderHook(() => useAxios(''))
Expand Down

0 comments on commit 4a63b6e

Please sign in to comment.