react-timer-mixin
TimerMixin provides timer functions for executing code in the future that are safely cleaned up when the component unmounts
Last updated 2 years ago by sophiebits .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install react-timer-mixin 
SYNC missed versions from official npm registry.

react-timer-mixin

Using bare setTimeout, setInterval, setImmediate and requestAnimationFrame calls is very dangerous because if you forget to cancel the request before the component is unmounted, you risk the callback throwing an exception.

If you include TimerMixin, then 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.

Installation

Install the module directly from npm:

npm install react-timer-mixin

Example

var React = require('react');
var TimerMixin = require('react-timer-mixin');

var Component = React.createClass({
  mixins: [TimerMixin],
  componentDidMount() {
    this.setTimeout(
      () => { console.log('I do not leak!'); },
      500
    );
  }
});

Current Tags

  • 0.13.4                                ...           latest (2 years ago)

5 Versions

  • 0.13.4                                ...           2 years ago
  • 0.13.3                                ...           4 years ago
  • 0.13.2                                ...           5 years ago
  • 0.13.1                                ...           5 years ago
  • 0.13.0                                ...           5 years ago
Downloads
Today 56
This Week 2,630
This Month 8,122
Last Day 164
Last Week 2,888
Last Month 8,904
Dependencies (0)
None
Dev Dependencies (2)
Dependents (432)

Copyright 2014 - 2016 © taobao.org |