Socket
Book a DemoInstallSign in
Socket

react-timer-safely

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-timer-safely

Timer functions for executing code in the future that are safely cleaned up when the react component unmounts.

latest
npmnpm
Version
0.1.0
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

TimerSafely

Timer functions for executing code in the future that are safely cleaned up when the react component unmounts.

Usage

You can replace your calls to setTimeout(fn, 500) with this.setTimeout(fn, 500) (just prepend this.) and everything will be properly cleaned up for you.

import React, { Component } from 'react'
import timerSafely from 'react-timer-safely'

@timerSafely
class TimerSafelyComponent extends Component {

  handleAsyncTimer = () => {
    // prepend `this.`
    this.setTimeout(fn, 500)
    this.setInterval(fn, 500)
    this.setImmediate(fn)
    this.requestAnimationFrame(fn)
  }

  rende() {
    return (
      <main>
        <button onClick={this.handleAsyncTimer}>async timer</button>
      </main>
    )
  }
}

License

react-timer-safely is released under the MIT license.

Keywords

timer

FAQs

Package last updated on 26 Dec 2016

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