react-timers icon indicating copy to clipboard operation
react-timers copied to clipboard

A react setInterval/setTimeout mixin for mere mortals

DEPRECATED: use react-timer-mixin instead

react-timers

Version

A 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

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