use-heart-beat
v0.4.1
Published
<!-- Title: use-heart-beat Description: polling and long-polling request in react hooks Author: JiangWeixian -->
Downloads
69
Maintainers
Readme
use-heart-beat
polling request in react hooks
Install
npm install use-heart-beat --save
Usage
see more props
use-polling
import React, { useState, useCallback } from 'react';
import { usePolling } from 'use-heart-beat';
import { api } from '@/api';
export default () => {
const fetch = useCallback(async () => {
return api.polling.polling(id);
}, []);
const { data } = usePolling<number>({ id: 'polling-example', api: fetch, delay: 1000 });
return (
<>
<span>{data}</span>
</>
);
};
use-long-polling
import React, { useState, useCallback } from 'react';
import { useLongPolling } from 'use-heart-beat';
import { api } from '@/api';
export default () => {
const fetch = useCallback(async () => {
return api.polling.longpolling(id);
}, []);
const { data } = useLongPolling<number>({ id: 'long-polling-example', api: fetch, delay: 1000 });
return (
<>
<span>{data}</span>
</>
);
};
Author
👤 JW
- Twitter: @jiangweixian
- Github: @JiangWeixian
Show your support
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator