Skip to content

Commit d379847

Browse files
committed
docs: update README
1 parent 528cfbe commit d379847

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,56 @@
11
# react-use-polling
2+
3+
![ci](https://github.com/hey3/react-use-polling/actions/workflows/test.yml/badge.svg)
4+
5+
`react-use-polling` is a react hooks library for polling asynchronous processes.
6+
7+
## Instration
8+
9+
```bash
10+
npm install react-use-polling
11+
```
12+
13+
## Quikstart
14+
15+
```tsx
16+
import { useState } from 'react'
17+
import { usePolling } from 'react-use-polling'
18+
19+
function App() {
20+
const [count, setCount] = useState<number>(0)
21+
22+
const updateCountAsync = async () => {
23+
await new Promise(r => setTimeout(r, 100))
24+
setCount(c => c + 1)
25+
}
26+
27+
const { pause } = usePolling(updateCountAsync, 1000)
28+
29+
return (
30+
<div>
31+
<span>{count}</span>
32+
<button onClick={() => pause()}>Pause Polling</button>
33+
</div>
34+
)
35+
}
36+
```
37+
38+
## Hooks
39+
40+
### `usePolling`
41+
42+
This hook uses `requestAnimationFrame`.
43+
It stops processing in the background to improving performance and reducing battery consumption.
44+
45+
### `usePollingForce`
46+
47+
This hook uses `setInterval`.
48+
This will continue the polling process even in the background.
49+
50+
## License
51+
52+
[MIT License](https://github.com/hey3/react-use-polling/blob/main/LICENSE)
53+
54+
## Author
55+
56+
Kohei Oyama ([@hey3](https://github.com/hey3))

0 commit comments

Comments
 (0)