You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue arises with an error message at this line stating that window is not defined: slidesOffsetBefore: (window.innerWidth - 1280)/2
I tried using useEffect and useState based on this solution that I found. However, the Swiper initializes only during the first render when the initial width is 0, before it sets to window.innerWidth.
How can I effectively utilize window.innerWidth in this scenario? Alternatively, is there a solution to use a percentage calculation like this? slidesOffsetBefore: calc((100% - 1280px)/2)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I use NextJS 14, and here is my code
The issue arises with an error message at this line stating that window is not defined:
slidesOffsetBefore: (window.innerWidth - 1280)/2
I tried using useEffect and useState based on this solution that I found. However, the Swiper initializes only during the first render when the initial width is 0, before it sets to window.innerWidth.
How can I effectively utilize window.innerWidth in this scenario? Alternatively, is there a solution to use a percentage calculation like this?
slidesOffsetBefore: calc((100% - 1280px)/2)
Beta Was this translation helpful? Give feedback.
All reactions