Fetch when the browser is online
You can use useOnline
to fetch a resource when the browser becomes online.
useOnline(query)
Example
function useAutoFetchMixture(query: Query) {
useFetch(query)
useVisible(query)
useOnline(query)
}
Implementation
export function useOnline(query: Query) {
const { fetch } = query
useEffect(() => {
const f = () => fetch()
addEventListener("online", f)
return () => removeEventListener("online", f)
}, [fetch])
}
See also
- useVisible - fetch when the tab is focused