1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-06-29 00:57:50 +02:00
market/src/@hooks/useAbortController.ts
mihaisc 487bcad8b4
Update ocean.js (#1013)
* update

* merge pr #1012

* fix header

* fix

* abort controller

* up next.8

* build fix

* update lock

* fix

* another fix

* ssh fix

* another ssh fix

* remove optional
2022-01-26 10:17:41 +00:00

18 lines
437 B
TypeScript

import { useRef, useEffect, useCallback } from 'react'
export const useAbortController = (): (() => AbortSignal) => {
const axiosSource = useRef(null)
const newAbortController = useCallback(() => {
axiosSource.current = new AbortController()
return axiosSource.current.signal
}, [])
useEffect(
() => () => {
if (axiosSource.current) axiosSource.current.abort()
},
[]
)
return newAbortController
}