Make client hoverable methods SSR compatible for NextJS

This commit is contained in:
Xevion
2022-12-24 15:18:23 -06:00
parent e0b68e829f
commit 601f4681ad

View File

@@ -2,8 +2,16 @@ export function classNames(...classes: (string | null | undefined)[]) {
return classes.filter(Boolean).join(" ");
}
const hoverableQuery = window.matchMedia('(hover: hover) and (pointer: fine)');
const isClient = (): boolean => {
return typeof window !== "undefined";
}
const isServer = (): boolean => {
return !isClient();
}
const hoverableQuery: MediaQueryList | null = isClient() ? window.matchMedia('(hover: hover) and (pointer: fine)') : null;
export function isHoverable() {
return hoverableQuery.matches;
return hoverableQuery?.matches;
}