1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00
market/src/@hooks/useCancelToken.ts
mihaisc c302122795
Add most viewed (#1754)
* 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>
2022-11-08 17:17:22 +00:00

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
}