ray-timer
v1.0.1
Published
timer for react
Downloads
6
Readme
ray-timer
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.
author
ilex.h
Install
npm i --save ray-timer
Usage
basic
import React from 'react';
import rayTimer from 'ray-timer';
class Demo extends {
componentDidMount() {
this.setTimeout(
() => { console.log('I do not leak, rayTimer will do clear!'); },
500
);
}
}
export default rayTimer(Demo);
Props
| Prop | Type | Opt/Required | Default | Note | |---|---|---|---|---|
License
MIT