use-heart-beat
    TypeScript icon, indicating that this package has built-in type declarations

    0.4.1 • Public • Published

    use-heart-beat

    Version License: MIT Twitter: jiangweixian

    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

    Show your support

    Give a ⭐️ if this project helped you!


    This README was generated with ❤️ by readme-md-generator

    Install

    npm i use-heart-beat

    DownloadsWeekly Downloads

    15

    Version

    0.4.1

    License

    MIT

    Unpacked Size

    30.3 kB

    Total Files

    12

    Last publish

    Collaborators

    • avatar