Socket
Socket
Sign inDemoInstall

react-timeout

Package Overview
Dependencies
34
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-timeout

Component wrapper for setTimeout et al that cleans up after itself.


Version published
Maintainers
1
Install size
25.2 kB
Created

Readme

Source

React Timeout

travis build npm version

A component wrapper providing safe-to-use-with-react versions of

SetClear
setTimeoutclearTimeout
setIntervalclearInterval
setImmediateclearImmediate
requestAnimationFramecancelAnimationFrame

When the component is unmounted the wrapper calls the Clear functions for you.

Installation

npm install --save react-timeout

React

import ReactTimeout from 'react-timeout'

React Native

The library also works with React Native ^0.16 and probably earlier versions:

import ReactTimeout from 'react-timeout/native'

Usage

Apply ReactTimeout using composition

class Example extends Component { .. }
const WithReactTimeout = ReactTimeout(Example)

or an annotation (not recommended)

@ReactTimeout
class WithReactTimeout extends Component { .. }

Invoke a safe setTimeout from within the component.

const { setTimeout } = this.props.reactTimeout
const id = setTimeout(() => {
  console.log(`The callback with ${id} fired!`)
}, 5000)

The callback function will be cleared if the component unmounts before the 5000ms elapse.

Example

A full example is available in example/src/example.js.

To run the example, clone the repository and run npm install && npm start in the example/ folder.

Inspiration

react-timer-mixin

The timer mixin recommended by the react-native README.md.

Mixins Are Dead. Long Live Composition

Dan Abramov's article promoting stuff like this package

Keywords

FAQs

Last updated on 06 Dec 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc