1.0.1 • Published 1 year ago

ray-timer v1.0.1

Weekly downloads
2
License
MIT
Repository
-
Last release
1 year ago

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

PropTypeOpt/RequiredDefaultNote

License

MIT