'use client';
import { useEffect, useRef } from 'react';
const FRAMES = 1;
export function useFavicon() {
const frame = useRef(0);
useEffect(() => {
const link = document.head.querySelector('link[rel="icon"]');
if (!link) return;
const scheme = window.matchMedia('(prefers-color-scheme: dark)');
function paint() {
const theme = scheme.matches ? 'dark' : 'light';
link?.setAttribute('href', `/favicons/${theme}/frame-${frame.current}.svg`);
}
paint();
const timer = setInterval(() => {
frame.current = (frame.current + 1) % FRAMES;
paint();
}, 1000);
scheme.addEventListener('change', paint);
return () => {
frame.current = 0;
clearInterval(timer);
scheme.removeEventListener('change', paint);
};
}, []);
}