Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reactjs/react-timer-mixin
TimerMixin provides timer functions for executing code in the future that are safely cleaned up when the component unmounts
https://github.com/reactjs/react-timer-mixin
Last synced: 6 days ago
JSON representation
TimerMixin provides timer functions for executing code in the future that are safely cleaned up when the component unmounts
- Host: GitHub
- URL: https://github.com/reactjs/react-timer-mixin
- Owner: reactjs
- License: mit
- Archived: true
- Created: 2015-03-20T10:20:53.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-07-17T07:07:49.000Z (over 6 years ago)
- Last Synced: 2024-10-29T20:25:03.856Z (3 months ago)
- Language: JavaScript
- Size: 17.6 KB
- Stars: 308
- Watchers: 16
- Forks: 42
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-react-native - react-native-timer-mixin ★274 - TimerMixin provides timer functions for executing code in the future that are safely cleaned up when the component unmounts. This is a fork that includes react-native InteractionManager support. (Components / UI)
- awesome-reactnative-ui - react-timer-mixin
- awesome-react-native - react-native-timer-mixin ★274 - TimerMixin provides timer functions for executing code in the future that are safely cleaned up when the component unmounts. This is a fork that includes react-native InteractionManager support. (Components / UI)
- awesome-react-native - react-native-timer-mixin ★274 - TimerMixin provides timer functions for executing code in the future that are safely cleaned up when the component unmounts. This is a fork that includes react-native InteractionManager support. (Components / UI)
- awesome-reactnative-ui - react-timer-mixin
- awesome-react-native - react-native-timer-mixin ★274 - TimerMixin provides timer functions for executing code in the future that are safely cleaned up when the component unmounts. This is a fork that includes react-native InteractionManager support. (Components / UI)
- awesome-react-native-ui - react-native-timer-mixin ★158 - TimerMixin provides timer functions for executing code in the future that are safely cleaned up when the component unmounts. This is a fork that includes react-native InteractionManager support. (Components / UI)
README
# 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
```js
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
);
}
});
```