前端: 添加useStats统计钩子
This commit is contained in:
parent
29c5dfc426
commit
62d3c30abb
23
frontend/src/renderer/hooks/useStats.js
Normal file
23
frontend/src/renderer/hooks/useStats.js
Normal 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;
|
||||
Loading…
Reference in New Issue
Block a user