├── .gitignore ├── LICENSE ├── README.md ├── examples ├── example1.html └── src │ └── example1.js ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Daniel Cousens 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DEPRECATED: use [react-timer-mixin](https://github.com/reactjs/react-timer-mixin) instead 2 | ### react-timers 3 | 4 | [](https://www.npmjs.org/package/react-timers) 5 | 6 | A [react](https://github.com/facebook/react) `setInterval`/`setTimeout` mixin for mere mortals. 7 | Any intervals that are set are automatically cleared based on the component life cycle. 8 | 9 | **WARNING:** If you are performing an async action, you should still check if the component is mounted. 10 | 11 | 12 | ## Example 13 | 14 | ``` javascript 15 | var Timers = require('react-timers') 16 | 17 | module.exports = React.createClass({ 18 | mixins: [Timers], 19 | 20 | componentDidMount: function () { 21 | var self = this 22 | 23 | this.setTimeout(function () { 24 | self.setState({ lastUpdated: new Date() }) 25 | }, 1000) 26 | 27 | this.setInterval(function () { 28 | self.setState({ lastUpdated: new Date() }) 29 | }, 1000) 30 | }, 31 | 32 | render: function () { 33 | // ... etc 34 | } 35 | }) 36 | ``` 37 | 38 | 39 | ## LICENSE [MIT](LICENSE) 40 | -------------------------------------------------------------------------------- /examples/example1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 |
13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/src/example1.js: -------------------------------------------------------------------------------- 1 | let React = require('react') 2 | let Timers = require('../../src/') 3 | 4 | let App = React.createClass({ 5 | mixins: [Timers], 6 | 7 | getInitialState () { 8 | return { 9 | text: new Date() 10 | } 11 | }, 12 | 13 | componentDidMount () { 14 | this.setInterval(() => { 15 | this.setState({ 16 | text: new Date() 17 | }) 18 | }, 1000) 19 | }, 20 | 21 | render () { 22 | return