From 5469c5d41a1e4d40b2aebde266dd7c4e2d2c8a95 Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 4 Apr 2024 08:33:24 +0000 Subject: fix window undefined error --- apps/web/src/hooks/useViewport.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'apps') diff --git a/apps/web/src/hooks/useViewport.ts b/apps/web/src/hooks/useViewport.ts index f24ed2d2..7ba90861 100644 --- a/apps/web/src/hooks/useViewport.ts +++ b/apps/web/src/hooks/useViewport.ts @@ -1,14 +1,21 @@ import { useState, useEffect } from "react"; function getViewport() { - const { innerWidth: width, innerHeight: height } = window ?? { - innerWidth: 0, - innerHeight: 0, - }; - return { - width, - height, - }; + try { + const { innerWidth: width, innerHeight: height } = window ?? { + innerWidth: 0, + innerHeight: 0, + }; + return { + width, + height, + }; + } catch { + return { + width: 0, + height: 0, + }; + } } export default function useViewport() { -- cgit v1.2.3