From 371c788ab7b58d68cc087c3f4dad69cd61b6c9e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Tue, 24 Nov 2020 11:42:21 +0100 Subject: [PATCH] refactor(react): refactor full height logic --- packages/docsearch-react/src/DocSearchModal.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/docsearch-react/src/DocSearchModal.tsx b/packages/docsearch-react/src/DocSearchModal.tsx index ff359a88..78132d7a 100644 --- a/packages/docsearch-react/src/DocSearchModal.tsx +++ b/packages/docsearch-react/src/DocSearchModal.tsx @@ -336,16 +336,20 @@ export function DocSearchModal({ // because all mobile browsers don't compute their height the same way. // See https://css-tricks.com/the-trick-to-viewport-units-on-mobile/ React.useEffect(() => { - const setFullViewportHeight = () => { + function setFullViewportHeight() { if (modalRef.current) { const vh = window.innerHeight * 0.01; modalRef.current.style.setProperty('--docsearch-vh', `${vh}px`); } - }; + } setFullViewportHeight(); + window.addEventListener('resize', setFullViewportHeight); - return () => window.removeEventListener('resize', setFullViewportHeight); + + return () => { + window.removeEventListener('resize', setFullViewportHeight); + }; }, []); return (