Skip to content

Commit

Permalink
fix: clean query listener
Browse files Browse the repository at this point in the history
  • Loading branch information
justypist committed Jun 19, 2024
1 parent 406f87e commit 39048a5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ export function useSwitchTheme() {

const query = window.matchMedia("(prefers-color-scheme: dark)");
meta.setAttribute("content", query.matches ? "#000000" : "#FFFFFF");
query.addEventListener("change", () => {
const updateThemeColor = (e: MediaQueryListEvent) => {
meta?.setAttribute("content", query.matches ? "#000000" : "#FFFFFF");
});
};
query.addEventListener("change", updateThemeColor);
return () => {
query.removeEventListener("change", updateThemeColor);
};
} else {
const themeColor = getCSSVar("--theme-color");
metaDescriptionDark?.setAttribute("content", themeColor);
Expand Down

0 comments on commit 39048a5

Please sign in to comment.