This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const isReachable = async () =>{ | |
const timeout = new Promise((resolve, reject) => { | |
setTimeout(reject, 5000, 'Request timed out'); | |
}); | |
const request = fetch('https://xxxxxx.com'); | |
try { | |
const response = await Promise | |
.race([timeout, request]); | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
const { useState, useEffect, useRef } = React | |
type IntervalFunction = () => ( unknown | void ) | |
function useInterval( callback: IntervalFunction, delay: number ) { | |
const savedCallback = useRef<IntervalFunction| null>( null ) |