0.0.3 • Published 3 years ago

use-fetch-on-interval v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

use-fetch-on-interval

A hook that allows you to fetch data on interval

NPM JavaScript Style Guide

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.