mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
c302122795
* add most viewed * Update src/components/Home/index.tsx Co-authored-by: Jamie Hewitt <jamie.hewitt15@gmail.com> * add views in teasers * typo * add test * switch to axios * test tweaks * fix * add 30 days label Co-authored-by: Jamie Hewitt <jamie.hewitt15@gmail.com> Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
21 lines
477 B
TypeScript
21 lines
477 B
TypeScript
import { useRef, useEffect, useCallback } from 'react'
|
|
import axios, { CancelToken } from 'axios'
|
|
|
|
export const useCancelToken = (): (() => CancelToken) => {
|
|
const axiosSource = useRef(null)
|
|
|
|
const newCancelToken = useCallback(() => {
|
|
axiosSource.current = axios.CancelToken.source()
|
|
return axiosSource?.current?.token
|
|
}, [])
|
|
|
|
useEffect(
|
|
() => () => {
|
|
if (axiosSource.current) axiosSource.current.cancel()
|
|
},
|
|
[]
|
|
)
|
|
|
|
return newCancelToken
|
|
}
|