mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-06 06:07:33 +02:00
Add useInterval hook
This commit is contained in:
16
client/hooks/useInterval.js
Normal file
16
client/hooks/useInterval.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
const useInterval = (callback, delay) => {
|
||||
useEffect(
|
||||
() => {
|
||||
const handler = () => callback();
|
||||
if (delay !== null) {
|
||||
const id = setInterval(handler, delay);
|
||||
return () => clearInterval(id);
|
||||
}
|
||||
},
|
||||
[delay]
|
||||
);
|
||||
};
|
||||
|
||||
export default useInterval;
|
Reference in New Issue
Block a user