0.0.3 • Published 3 years ago
use-fetch-on-interval v0.0.3
use-fetch-on-interval
A hook that allows you to fetch data on interval
Install
npm install --save use-fetch-on-interval
Usage
import React from 'react'
import axios from 'axios'
import useFetchOnInterval from 'use-fetch-on-interval'
function fetchDataWithAxios() {
return axios.get('./data.json')
}
const oneSecond = 1000
const interval = oneSecond
const App = () => {
const { data, error, isLoading } = useFetchOnInterval(fetchDataWithAxios, interval)
return (
<div>
<p>
<code>DATA: {JSON.stringify(data)}</code>
</p>
<p>
<code>ERROR: {JSON.stringify(error)}</code>
</p>
<p>
<code>IS_LOADING: {JSON.stringify(isLoading)}</code>
</p>
</div>
)
}
export default App
License
MIT © szabikr
This hook is created using create-react-hook.