v2.5.9
Feat: responseTime
and useResponseTime
Adds useResponseTime
hook that returns the time (in miliseconds) it took to complete a request. Example:
import { useFetch } from 'http-react'
function App() {
const { data, loading, error, responseTime } = useFetch('/api/profile')
if (loading) return <p>Loading</p>
if (error) return <p>Error</p>
return (
<div>
<p>Email: {data?.email}</p>
<small>Completed in {responseTime} miliseconds</small>
</div>
)
}
If you wanted to get the response time from another component/hook, you can do so by using the useResponseTime
hook, which takes the id
of the request as argument. Because we did not pass an id to the useFetch
call above, we can use the method and the url instead:
import { useResponseTime } from 'http-react'
function ResponseTimeBanner() {
const responseTime = useResponseTime('GET /api/profile')
return <small>Completed in {responseTime} miliseconds</small>
}