QCIC

Stale While Revalidate

  • See docs here

Output:

useSWR('https://time.qcic.n.imetrical.com/',fetcher,{"refreshInterval":1000})
{
  "isValidating": false,
  "isLoading": true
}

Code

import React from 'react'
import useSWR from 'swr'
// Picked (un)fetch, because it is now polyfilled with next.js
import fetch from 'unfetch'
const fetcher = url => fetch(url).then(r => r.json())
export function ClockFetchInterval ({
url = 'https://time.qcic.n.imetrical.com/',
refreshInterval = 1000
}) {
const { data, error, isValidating } = useSWR(url, fetcher, { refreshInterval })
const isLoading = !error && !data
const pretty = JSON.stringify({ isValidating, isLoading, error, data }, null, 2)
return (
<div>
<div>useSWR('{url}',fetcher,{JSON.stringify({ refreshInterval })})</div>
<pre>{pretty}</pre>
</div>
)
}