mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
17 lines
364 B
TypeScript
17 lines
364 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) {
|
||
|
useLayoutEffect(() => {
|
||
|
callback(fetchMock)
|
||
|
|
||
|
return () => {
|
||
|
fetchMock.restore()
|
||
|
}
|
||
|
}, [callback])
|
||
|
}
|