Download ui/src/hooks/useCPUInfo.tsx from michaelu0826/ai_toolkit_code: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/datasets/michaelu0826/ai_toolkit_code/resolve/main/ui/src/hooks/useCPUInfo.tsx
- Command line
-
hf download hf://datasets/michaelu0826/ai_toolkit_code/ui/src/hooks/useCPUInfo.tsx
-
curl -L -o useCPUInfo.tsx https://huggingface.co/datasets/michaelu0826/ai_toolkit_code/resolve/main/ui/src/hooks/useCPUInfo.tsx
1.31 kB
| 'use client'; | |
| import { CpuInfo } from '@/types'; | |
| import { useEffect, useState } from 'react'; | |
| import { apiClient } from '@/utils/api'; | |
| export default function useCPUInfo(reloadInterval: null | number = null) { | |
| const [cpuInfo, setCpuInfo] = useState<CpuInfo | null>(null); | |
| const [isCPUInfoLoaded, setIsLoaded] = useState(false); | |
| const [status, setStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle'); | |
| const fetchCpuInfo = async () => { | |
| setStatus('loading'); | |
| try { | |
| const data: CpuInfo = await apiClient.get('/api/cpu').then(res => res.data); | |
| setCpuInfo(data); | |
| setStatus('success'); | |
| } catch (err) { | |
| console.error(`Failed to fetch CPU data: ${err instanceof Error ? err.message : String(err)}`); | |
| setStatus('error'); | |
| } finally { | |
| setIsLoaded(true); | |
| } | |
| }; | |
| useEffect(() => { | |
| // Fetch immediately on component mount | |
| fetchCpuInfo(); | |
| // Set up interval if specified | |
| if (reloadInterval) { | |
| const interval = setInterval(() => { | |
| fetchCpuInfo(); | |
| }, reloadInterval); | |
| // Cleanup interval on unmount | |
| return () => { | |
| clearInterval(interval); | |
| }; | |
| } | |
| }, [reloadInterval]); // Added dependencies | |
| return { cpuInfo, isCPUInfoLoaded, status, refreshCpuInfo: fetchCpuInfo }; | |
| } | |