Timers are an important part of an application and React VR implements the browser timers.
requestAnimationFrame(fn) is not the same as
setTimeout(fn, 0). The former fires after all of the frame has flushed, whereas the latter fires as quickly as possible (over 1000x per second on a iPhone 5S).
setImmediate within a
setImmediate callback, it will be executed right away, and it won't yield back to native in between.
Promise implementation uses
setImmediate as its asynchronicity primitive.
We discovered that the primary cause of fatal system errors in React VR apps was timers firing after a component was unmounted. To solve this recurring issue, we introduced
TimerMixin. If you include
TimerMixin, you can replace your calls to
setTimeout(fn, 500) with
this.setTimeout(fn, 500) and everything is properly cleaned up for you when the component unmounts.
This library does not ship with React VR. To use it in your project, install it with
npm i react-timer-mixin --save from your project directory.
Using this library mitigates some of the hard work tracking down system crashes.
You can file an issue on GitHub if you see a typo or error on this page!