Skip to content

Commit

Permalink
Create useInterval.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 24, 2024
1 parent 09aa772 commit f4ba8dc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/pages/Dashboard/hooks/useInterval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useState, useEffect } from 'react';

const useInterval = (callback, delay) => {
const [intervalId, setIntervalId] = useState(null);

useEffect(() => {
const interval = setInterval(callback, delay);
setIntervalId(interval);
return () => clearInterval(interval);
}, [callback, delay]);

return intervalId;
};

export default useInterval;

0 comments on commit f4ba8dc

Please sign in to comment.