I am getting error while building the app for the production. And it kept saying that
ReferenceError: window is not defined. I am lost to solve the problem
FullCode:
const [windowSize, setWindowSize] = useState<WindowInfo>({
width: window.innerWidth,
height: window.innerHeight,
});
useEffect(() => {
if (typeof window !== "undefined") { // error showing in this line
function handleResize() {
const data: WindowInfo = {
width: window.innerWidth,
height: window.innerHeight,
}
setWindowSize(data);
}
window.addEventListener("resize", handleResize);
handleResize();
return () => window.removeEventListener("resize", handleResize);
}
}, []);
anyone can tell me the workaround of this problem