1.0.0 • Published 3 years ago
react-use-polling v1.0.0
react-use-polling
react-use-polling is a react hooks library for polling asynchronous processes.
Instration
npm install react-use-pollingQuikstart
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
Author
Kohei Oyama (@hey3)
1.0.0
3 years ago