GithubHelp home page GithubHelp logo

jiangweixian / use-heart-beat Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 911 KB

polling request in react hooks

License: MIT License

JavaScript 18.04% TypeScript 77.20% CSS 4.76%
polling long-polling react-hooks react

use-heart-beat's Introduction

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

use-heart-beat's People

Contributors

jiangweixian avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.