You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openhamclock/src/hooks/useContests.js

35 lines
827 B

/**
* useContests Hook
* Fetches upcoming amateur radio contests
*/
import { useState, useEffect } from 'react';
export const useContests = () => {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchContests = async () => {
try {
const response = await fetch('/api/contests');
if (response.ok) {
const contests = await response.json();
setData(contests);
}
} catch (err) {
console.error('Contests error:', err);
} finally {
setLoading(false);
}
};
fetchContests();
const interval = setInterval(fetchContests, 30 * 60 * 1000); // 30 minutes
return () => clearInterval(interval);
}, []);
return { data, loading };
};
export default useContests;

Powered by TurnKey Linux.