1.0.0 • Published 1 year ago

react-use-polling v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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)