# react-hoc-timerfuncs **Repository Path**: sethyuan/react-hoc-timerfuncs ## Basic Information - **Project Name**: react-hoc-timerfuncs - **Description**: Timer functions provided via props that auto clear themselves at unmount - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-26 - **Last Updated**: 2021-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # react-hoc-timerfuncs **NOTE: This project is OBSOLETE, most of its functionalities are better implemented in [reactutils](https://gitee.com/sethyuan/reactutils).** This 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 ## Installation ```bash yarn add react-hoc-timerfuncs ``` ## Example ```js // ... import timer from "react-hoc-timerfuncs" @timer class Counter extends React.Component { state = { counter: 0 } render() { return (
{this.state.counter}
) } componentDidMount() { // Instead of standard functions you will use the functions // provided by props. this.props.setInterval(() => { this.setState(state => ({ counter: state.counter + 1 })) }, 10) } } ``` ## Dev setup 1. `yarn` ### npm run tasks - **yarn build**: Transpile source code