polling request in react hooks
npm install use-heart-beat --save
see more props
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>
</>
);
};
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>
</>
);
};
👤 JW
- Twitter: @jiangweixian
- Github: @JiangWeixian
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator