"ReferenceError: window is not defined" in Next.JS Project #44
-
I am attempting to use react-dymo-hooks in a Next.JS project and as soon as I call any of the functions, including a simple Disabling all references to react-dymo causes the error to disappear. Running Any suggestions for things I can try? Thank you!
EDIT: After doing some more research, this appears to be due to Next.JS using Server Side Rendering and react-dymo assuming there is a window for it do local storage in. One suggestion I found is to wrap things in useEffect() but I believe that would break the Rules of Hooks, right? I will continue to research, but any suggestions are appreciated. ANOTHER EDIT: It looks like I should be able to fix it by marking the component I'm using the library in as client only with the "use client" directive, but the error is happening even after doing that. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Final update: The reason |
Beta Was this translation helpful? Give feedback.
Final update:
The reason
"use client"
was not working is because I was still using the olderpages/
routing structure which only exists as backwards compatibility. Switching into the newerapp/
router honored"use client"
and it is working now.