I found that, when changing pages in an SPA (React + Next.js in this case), sometimes handleResize is called after the container element is unmounted from the DOM (so containerRef.current is null), but before the responsive nav component is removed from the VDOM, causing an error during page change. Adding a null check fixes this.
I found that, when changing pages in an SPA (React + Next.js in this case), sometimes
handleResize
is called after the container element is unmounted from the DOM (socontainerRef.current
is null), but before the responsive nav component is removed from the VDOM, causing an error during page change. Adding a null check fixes this.