Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dcousens/react-timers

A react setInterval/setTimeout mixin for mere mortals
https://github.com/dcousens/react-timers

Last synced: 24 days ago
JSON representation

A react setInterval/setTimeout mixin for mere mortals

Awesome Lists containing this project

README

        

# DEPRECATED: use [react-timer-mixin](https://github.com/reactjs/react-timer-mixin) instead
### react-timers

[![Version](http://img.shields.io/npm/v/react-timers.svg)](https://www.npmjs.org/package/react-timers)

A [react](https://github.com/facebook/react) `setInterval`/`setTimeout` mixin for mere mortals.
Any intervals that are set are automatically cleared based on the component life cycle.

**WARNING:** If you are performing an async action, you should still check if the component is mounted.

## Example

``` javascript
var Timers = require('react-timers')

module.exports = React.createClass({
mixins: [Timers],

componentDidMount: function () {
var self = this

this.setTimeout(function () {
self.setState({ lastUpdated: new Date() })
}, 1000)

this.setInterval(function () {
self.setState({ lastUpdated: new Date() })
}, 1000)
},

render: function () {
// ... etc
}
})
```

## LICENSE [MIT](LICENSE)