useInterval

Provides a convenient way to create and manage intervals.

Usage

import React, { useState } from "react";
import useInterval from 'funda-ui/Utils/useIntervalx';
 
 
const App = () => {
    const [count, setCount] = useState(0);
    const [list, setList] = useState([]);
 
    const { startTimer, stopTimer } = useInterval(() => {
        setCount(count + 1);
    }, 1000);
 
    const { startTimer: startTimerGetList, stopTimer: stopTimerGetList } = useInterval(() => {
        setList((prevState) => {
            return [...prevState, Math.random()]
        });
    }, 1000, false);
 
    const handleGetList = () => {
        startTimerGetList();
    };
 
    useEffect(() => {
        handleGetList();
    }, []);
 
    return (
        <div className="app">{count}{list.join(',')}</div>
    );
};