GT2/GT2-iOS/node_modules/react-timer-mixin
Ren Ren Juan 30eef7d036 correct tree err 2018-02-12 17:26:06 +00:00
..
__tests__ correct tree err 2018-02-12 17:26:06 +00:00
.eslintignore correct tree err 2018-02-12 17:26:06 +00:00
.eslintrc correct tree err 2018-02-12 17:26:06 +00:00
.npmignore correct tree err 2018-02-12 17:26:06 +00:00
CONTRIBUTING.md correct tree err 2018-02-12 17:26:06 +00:00
LICENSE correct tree err 2018-02-12 17:26:06 +00:00
PATENTS correct tree err 2018-02-12 17:26:06 +00:00
README.md correct tree err 2018-02-12 17:26:06 +00:00
TimerMixin.js correct tree err 2018-02-12 17:26:06 +00:00
package.json correct tree err 2018-02-12 17:26:06 +00:00

README.md

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
    );
  }
});