Skip to content

A TimerEnhance for React Native app (es6) which replaced TimerMixin (es5) provides timer functions for executing code in the future that are safely cleaned up when the component unmounts

License

Notifications You must be signed in to change notification settings

react-native-component/react-native-smart-timer-enhance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-smart-timer-enhance

npm npm npm npm

A TimerEnhance for React Native app (es6) which replaced TimerMixin (es5) provides timer functions for executing code in the future that are safely cleaned up when the component unmounts

Inspired by react-timer-mixin

Installation

npm install react-native-smart-timer-enhance --save

Full Demo

see ReactNativeComponentDemos

Usage

Install the TimerEnhance from npm with npm install react-native-smart-timer-enhance --save. Then, require it from your app's JavaScript files with import TimerEnhance from 'react-native-smart-timer-enhance'.

import React, {
    Component,
} from 'react'

import TimerEnhance from 'react-native-smart-timer-enhance'

class TimerEnhanceDemo extends Component {

    componentDidMount() {
        this.setTimeout(() => {
            console.log('setTimeout do not leak!');
        }, 3000);
        this.setInterval( () => {
            console.log('setInterval do not leak!');
        }, 1000)
        this.requestAnimationFrame(this._raf)
    }

    render() {
        return null
    }

    _raf = (...p) => {
        console.log('requestAnimationFrame do not leak!');
        this.requestAnimationFrame(this._raf)
    }
}

export default TimerEnhance(TimerEnhanceDemo)

About

A TimerEnhance for React Native app (es6) which replaced TimerMixin (es5) provides timer functions for executing code in the future that are safely cleaned up when the component unmounts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published