# react-native-timer-mixin

> 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.

Latest version **0.11.0** (published 2015-10-09) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install react-native-timer-mixin
pnpm add react-native-timer-mixin
yarn add react-native-timer-mixin
bun add react-native-timer-mixin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.11.0 |
| Published | 2015-10-09 |
| First published | 2015-09-12 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 308 |
| Maintainers | brentvatne, ccheever, exponent, ide |
| Keywords | react, timer, mixin, react-native |

## Links

- npm: https://www.npmjs.com/package/react-native-timer-mixin
- Repository: https://github.com/reactjs/react-timer-mixin
- Homepage: https://github.com/reactjs/react-timer-mixin#readme
- Issues: https://github.com/reactjs/react-timer-mixin/issues
- npm.io page: https://npm.io/package/react-native-timer-mixin

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.11.0 (latest) — 2015-10-09
- 0.10.3 — 2015-10-09
- 0.10.2 — 2015-09-12
- 0.10.1 — 2015-09-12
- 0.10.0 — 2015-09-12

## README

# react-native-timer-mixin

Fork of
[react-timer-mixin](https://github.com/reactjs/react-timer-mixin) to add
integration with the react-native `InteractionManager`.

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.

## Installation

Install the module directly from npm:

```
npm install react-native-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);
    this.runAfterInteractions(() => {
      console.log('I also do not leak, unless you want me to ;)');
    });
  }
});
```

## TODO

- [ ] Mock out InteractionManager and add tests.

---
_Source: https://npm.io/package/react-native-timer-mixin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
