25 lines
400 B
JavaScript
25 lines
400 B
JavaScript
import { useState, useEffect } from "react";
|
|
|
|
|
|
const useRefresh = (interval) => {
|
|
const [t, setT] = useState(1);
|
|
|
|
useEffect(() => {
|
|
let h = null;
|
|
if (interval) {
|
|
h = setInterval(() => {
|
|
setT(Date.now());
|
|
}, interval);
|
|
}
|
|
return () => {
|
|
if (interval) {
|
|
clearInterval(h);
|
|
}
|
|
};
|
|
}, [interval]);
|
|
|
|
return t;
|
|
};
|
|
|
|
export default useRefresh;
|