Use svelte:window to bind winWidth to improve SSR

Removed handler
This commit is contained in:
Amandeep 2020-03-08 20:00:45 -04:00 committed by GitHub
commit ee27d7b8cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,23 +18,13 @@
let isSideNavOpen = undefined; let isSideNavOpen = undefined;
let winWidth = undefined; let winWidth = undefined;
$: isSideNavOpen = winWidth >= 1056
onMount(() => {
winWidth = window.innerWidth
window.addEventListener('resize', () => {
winWidth = window.innerWidth;
if (winWidth >= 1056) {
isSideNavOpen = true;
} else {
isSideNavOpen = false;
}
});
})
$: ariaLabel = company + (uiShellAriaLabel || $$props['aria-label'] || platformName); $: ariaLabel = company + (uiShellAriaLabel || $$props['aria-label'] || platformName);
</script> </script>
<svelte:window bind:innerWidth={winWidth} />
<header aria-label={ariaLabel} class={cx('--header')} role="banner"> <header aria-label={ariaLabel} class={cx('--header')} role="banner">
{#if winWidth < 1056} {#if winWidth < 1056}
<HamburgerMenu bind:isOpen={isSideNavOpen} /> <HamburgerMenu bind:isOpen={isSideNavOpen} />