react-hook-interval

    1.0.1 • Public • Published

    react-hook-interval

    A component of React Hook based on setInterval and clearInterval that supports multi-interval management.

    Install

    Using npm

    npm install react-hook-interval --save-dev

    Usage

    ESM usage

    import useInterval from 'react-hook-interval';
    
    export default function myComponent() {
        const { setInterval, clearInterval } = useInterval();
        let id = setInterval(() => {
            console.log(Date.now());
            clearInterval(id)
        }, 5000);
    }
    

    Description

    This hook component supports to remove all interval automatically when component uninstalled.

    Method

    setInterval(callback, delay)

    • callback => {Function} The callback function for the interval response.(required)
    • delay => {Number} Delay time.(required)
    • return value => {Number} Interval ID

    clearInterval(id)

    • id => {Number} Interval ID.(required)

    License

    react-hook-interval is MIT licensed.

    Install

    npm i react-hook-interval

    DownloadsWeekly Downloads

    1

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    7.34 kB

    Total Files

    7

    Last publish

    Collaborators

    • amoydreamer