前端: 添加useStats统计钩子

This commit is contained in:
Frontend Developer 2026-03-10 09:39:41 +00:00
parent 29c5dfc426
commit 62d3c30abb

View File

@ -0,0 +1,23 @@
import { useState, useEffect } from 'react';
import api from '../utils/api';
export const useStats = () => {
const [stats, setStats] = useState(null);
const [loading, setLoading] = useState(false);
const fetchStats = async () => {
setLoading(true);
try {
const data = await api.get('/api/stats');
setStats(data);
} finally {
setLoading(false);
}
};
useEffect(() => { fetchStats(); }, []);
return { stats, loading, refetch: fetchStats };
};
export default useStats;