New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-use-poll

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-poll

React polling hook

latest
Source
npmnpm
Version
1.1.5
Version published
Weekly downloads
53
-14.52%
Maintainers
1
Weekly downloads
 
Created
Source

react-use-poll

Codecov Coverage GitHub

Purpose

react-use-poll is a package designed to simplify polling in functional react components.

Installation

Add to your project using npm i -S react-use-poll

How to use

The simplest possible use is below.

import React from 'react';
import usePoll from 'react-use-poll';

export default function MyComponent() {
  usePoll(() => {
    console.log('Hello world!');
  });
}

// Will log 'Hello world!' once every 5 seconds

It supports dependencies in the same way that useEffect does, to restart the poll.

import React from 'react';
import usePoll from 'react-use-poll';

export default function MyComponent({ prop1 }) {
  usePoll(() => {
    console.log('Hello world!');
  }, [prop1]);
}

// Will log 'Hello world!' once every 5 seconds

It supports asynchronous callbacks. The polling timeout will start at the point that the async function completes.

import React from 'react';
import usePoll from 'react-use-poll';

export default function MyComponent() {
  usePoll(async () => {
    await fetch();
    console.log('Hello world!');
  });
}

// Will log 'Hello world!' once every 5 seconds + however long the async function takes to respond

It supports different callback times.

import React from 'react';
import usePoll from 'react-use-poll';

export default function MyComponent() {
  usePoll(async () => {
    await fetch();
    console.log('Hello world!');
  }, [], {
    interval: 3000
  });
}

// Will log 'Hello world!' once every 3 seconds

Keywords

react

FAQs

Package last updated on 07 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts