react-use-polling
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

react-use-polling

ci

react-use-polling is a react hooks library for polling asynchronous processes.

Instration

npm install react-use-polling

Quikstart

import { useState } from 'react'
import { usePolling } from 'react-use-polling'

function App() {
  const [count, setCount] = useState<number>(0)

  const updateCountAsync = async () => {
    await new Promise(r => setTimeout(r, 100))
    setCount(c => c + 1)
  }

  const { pause } = usePolling(updateCountAsync, 1000)

  return (
    <div>
      <span>{count}</span>
      <button onClick={() => pause()}>Pause Polling</button>
    </div>
  )
}

Hooks

usePolling

This hook uses requestAnimationFrame.
It stops processing in the background to improving performance and reducing battery consumption.

usePollingForce

This hook uses setInterval.
This will continue the polling process even in the background.

License

MIT License

Author

Kohei Oyama (@hey3)

Install

npm i react-use-polling

DownloadsWeekly Downloads

10

Version

1.0.0

License

MIT

Unpacked Size

20.3 kB

Total Files

17

Last publish

Collaborators

  • hey3