Fix History component useEffect dependency array
This commit is contained in:
1 parent
c7ebc5aff3
commit
3c947ef6a3
1 file changed
+12
-13
+12
-13
@@ -19,21 +19,20 @@ function History() {
|
|||||||
const [days, setDays] = useState(7);
|
const [days, setDays] = useState(7);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const loadHistory = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const response = await axios.get('/api/history/overview', { params: { days } });
|
|
||||||
setHistoryData(response.data);
|
|
||||||
setLoading(false);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading history:', error);
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const loadHistory = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await axios.get('/api/history/overview', { params: { days } });
|
||||||
|
setHistoryData(response.data);
|
||||||
|
setLoading(false);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading history:', error);
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
loadHistory();
|
loadHistory();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, [days]);
|
}, [days]);
|
||||||
|
|
||||||
if (loading) return <div className="container">Loading history...</div>;
|
if (loading) return <div className="container">Loading history...</div>;
|
||||||
|
|||||||
Reference in new issue
Block a user