Timer functions provided via props that auto clear themselves at unmount
npm install react-hoc-timerfuncsThis HOC (Higher Order Component) provides the following timer like functions
via props that will get automatically cleared when component gets unmounted.
Can be used with both React and React Native.
- setTimeout
- setInterval
- setImmediate
- requestAnimationFrame
- clearTimeout
- clearInterval
- clearImmediate
- cancelAnimationFrame
``bash`
yarn add react-hoc-timerfuncs
`js
// ...
import timer from "react-hoc-timerfuncs"
@timer
class Counter extends React.Component {
state = {
counter: 0
}
render() {
return (
componentDidMount() {
// Instead of standard functions you will use the functions
// provided by props.
this.props.setInterval(() => {
this.setState(state => ({ counter: state.counter + 1 }))
}, 10)
}
}
`
1. yarn`
- yarn build: Transpile source code