I don't get what your point is, are you asking for help?
It's normal to get an error, window is not defined on the server. Remember that Next runs your code on the server when building the HTML file.
window
Initialise your state to 0 and update it to window.innerWidth in useEffect.
window.innerWidth
can u show me how to do it?
Something like that:
const [windowWidth, setWindowWidth] = useState(0) // runs only once, on mount useEffect(() => { if (window !== undefined){ setWindowWidth(window.innerWidth) window.addEventListener('resize', handleWindowWidth) } }, [])
Thank You.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I don't get what your point is, are you asking for help?
It's normal to get an error,
window
is not defined on the server. Remember that Next runs your code on the server when building the HTML file.Initialise your state to 0 and update it to
window.innerWidth
in useEffect.can u show me how to do it?
Something like that:
Thank You.