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

react-timeout

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-timeout

A version of react-timer-mixin without the mixin part

  • 0.14.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-4.62%
Maintainers
1
Weekly downloads
 
Created
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

Usage

Import and apply ReactTimeout using composition

import ReactTimeout from 'react-timeout'

class Simple extends Component { .. }
const Timeoutable = ReactTimeout(Simple)

or an annotation (not recommended)

import ReactTimeout from 'react-timeout'

@ReactTimeout
class Timeoutable 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 time elapses.

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 musing on why a project like this might be a good idea.

FAQs

Package last updated on 19 Nov 2015

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