Safe React wrapper for setInterval
Safe React wrapper for setInterval



``sh`
npm install --save react react-interval
Don't forget to manually install peer dependencies (react) if you use npm@3.
`htmlReactInterval
(Module exposed as )`
http://nkbt.github.io/react-interval
http://codepen.io/nkbt/pen/ZGmpoO
`js
import ReactInterval from 'react-interval';
const App = React.createClass({
getInitialState() {
return {count: 0};
},
render() {
const {count} = this.state;
return (
$3
Change timeout on the fly, start and stop counting`js
import React from 'react';
import ReactDOM from 'react-dom';
import ReactInterval from 'react-interval';const App = React.createClass({
getInitialState() {
return {
enabled: false,
timeout: 1000,
count: 0
};
},
render() {
const {timeout, enabled, count} = this.state;
return (
callback={() => this.setState({count: this.state.count + 1})} /> onChange={({target: {value}}) => this.setState({timeout: parseInt(value, 10)})} />
{count}
);
}
});const appRoot = document.createElement('div');
document.body.appendChild(appRoot);
ReactDOM.render( , appRoot);
`Options
####
callback: PropTypes.func.isRequiredFunction repeatedly called after timeout
####
enabled: PropTypes.bool (default: false)Should start timer?
####
timeout: PropTypes.number (default: 1000)Timeout before each
callback` callMIT