mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-18 02:30:51 +08:00
feat: initialize new React application structure with TypeScript, ESLint, and Prettier configurations, while removing legacy files and adding new components and pages for enhanced functionality
This commit is contained in:
24
src/hooks/useInterval.ts
Normal file
24
src/hooks/useInterval.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 定时器 Hook
|
||||
*/
|
||||
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
export function useInterval(callback: () => void, delay: number | null) {
|
||||
const savedCallback = useRef<(() => void) | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
savedCallback.current = callback;
|
||||
}, [callback]);
|
||||
|
||||
useEffect(() => {
|
||||
if (delay === null) return;
|
||||
|
||||
const tick = () => {
|
||||
savedCallback.current?.();
|
||||
};
|
||||
|
||||
const id = setInterval(tick, delay);
|
||||
return () => clearInterval(id);
|
||||
}, [delay]);
|
||||
}
|
||||
Reference in New Issue
Block a user