window is not defined #13148
Answered
by
jamesmosier
Tatametheus
asked this question in
Help
-
The following codes given the error window is not defined in the terminal console. How can I get the window and set it to domTarget?
|
Beta Was this translation helpful? Give feedback.
Answered by
jamesmosier
May 20, 2020
Replies: 1 comment 1 reply
-
You'll have to wait for the client to render this, as You could conditionally load this component by checking if Otherwise you could try: const bind = useScroll(
({ xy: [, y] }) => set({ width: (y / height) * 100 + '%' }),
{ domTarget: typeof window !== 'undefined ? window : null }
) As a last resort you could import this |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
rafaelalmeidatk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll have to wait for the client to render this, as
window
is not available on the server or when this page is built.You could conditionally load this component by checking if
typeof window !== 'undefined'
then render the component.Otherwise you could try:
As a last resort you could import this
ScrollExample
component using a dynamic import withsrr: false
as shown in the docs