react-timer-mixin to add
integration with the react-native
Using bare setTimeout, setInterval, setImmediate, requestAnimationFrame and InteractionManager.runAfterInteractions calls is very dangerous because if you forget to cancel the request before the component is unmounted, you risk the callback throwing an exception. In the case of InteractionManager.createInteractionHandle you also want to be sure that the handle is cleaned up if for whatever reason the component is unmounted before that has a chance to occur.
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.
Install the module directly from npm:
npm install react-native-timer-mixin
var React = ;var TimerMixin = ;var Component = React;
- Mock out InteractionManager and add tests.