Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-hoc-timers

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hoc-timers

A higher-order component of React based on setInterval, clearInterval, setTimeout and clearTimeout that support multi-timers management.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-hoc-timers

A higher-order component of React based on setInterval, clearInterval, setTimeout and clearTimeout that support multi-timers management.

Install

Using npm

npm install react-hoc-timers --save-dev

Usage

import

CommonJS
const Timer = require('react-hoc-timers')
ESM
import Timer from 'react-hoc-timers'

Call HOC

const EnhancedComponent = Timer(MyComponent)

You can use the Decorator feature of ECMAScript 6, like this

@Timer
class MyComponent extends React.component {}

Call the method of HOC

class MyComponent extends React.component {
    constructor(props) {
    	super(props)
    }
    componentDidMount() {
        const { setInterval, clearInterval, setTimeout } = this.props
        // call setInterval
        let id = setInterval(() => {
            console.log('interval')
            // call clearInterval
            clearInterval(id)
        }, 3000)
        // call setTimeout
        setTimeout(() => {
            console.log('timeout')
        }, 5000)
    }
}

Description

This higher-order component supports to remove all timers automatically when component uninstalled.

Method

setInterval(callback, delay)

  • callback => {Function} The callback function for the interval response.(required)
  • delay => {Number} Delay time.(required)
  • return value => {Number} Interval ID

clearInterval(id)

  • id => {Number} Interval ID.(required)

setTimeout(callback, delay)

  • callback => {Function} The callback function for the timeout response.(required)
  • delay => {Number} Delay time.(required)
  • return value => {Number} Timeout ID

clearTimeout(id)

  • id => {Number} Timeout ID.(required)

License

react-hoc-timers is MIT licensed.

Keywords

FAQs

Package last updated on 08 Jul 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc