mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 02:23:41 -05:00
910e07ca1c
GitOrigin-RevId: 41ee6b6873a01fbfedc41a884b9e3ebee47fc08f
18 lines
403 B
TypeScript
18 lines
403 B
TypeScript
import { useLayoutEffect } from 'react'
|
|
import fetchMock from 'fetch-mock'
|
|
fetchMock.config.fallbackToNetwork = true
|
|
|
|
/**
|
|
* Run callback to mock fetch routes, call restore() when unmounted
|
|
*/
|
|
export default function useFetchMock(
|
|
callback: (value: typeof fetchMock) => void
|
|
) {
|
|
useLayoutEffect(() => {
|
|
callback(fetchMock)
|
|
|
|
return () => {
|
|
fetchMock.restore()
|
|
}
|
|
}, [callback])
|
|
}
|