Check for window to exist

This commit is contained in:
ernstmul committed 2025-01-29 16:55:45 +01:00
1 parent 83f081aafc
commit e71fc08b2f
1 file changed
+8 -2
+8 -2
View File
@@ -3,11 +3,17 @@ import { writable } from 'svelte/store';
const isSmallViewport = writable(false);
function updateViewport() {
isSmallViewport.set(window.matchMedia('(max-width: 768px)').matches);
if (typeof window !== 'undefined') {
isSmallViewport.set(
typeof window !== 'undefined' ? window.matchMedia('(max-width: 768px)').matches : false
);
}
}
// Initialize on import
updateViewport();
window.addEventListener('resize', updateViewport);
if (typeof window !== 'undefined') {
window.addEventListener('resize', updateViewport);
}
export { isSmallViewport };