error ReferenceError: window is not definedGetting this error even though using 'use client'
Answered
Cuban Crocodile posted this in #help-forum
Cuban CrocodileOP
const [state, dispatch] = React.useReducer(authReducer, {
status: window.localStorage.getItem("userdetails") ? AuthStatus.authchecking : AuthStatus.unauthenticated,
});Answered by B33fb0n3
Check inside your code if your window is undefined. Only execute your function, when it’s defined.
That’s a proper solution: https://stackoverflow.com/questions/71548926/window-is-not-defined-in-nextjs
That’s a proper solution: https://stackoverflow.com/questions/71548926/window-is-not-defined-in-nextjs
2 Replies
Check inside your code if your window is undefined. Only execute your function, when it’s defined.
That’s a proper solution: https://stackoverflow.com/questions/71548926/window-is-not-defined-in-nextjs
That’s a proper solution: https://stackoverflow.com/questions/71548926/window-is-not-defined-in-nextjs
Answer
Cuban CrocodileOP
Cool got it thanks