-
-
Save ciel334288/f18ae272c14b5303da8506b9c91ab536 to your computer and use it in GitHub Desktop.
handle window object load for Nextjs/SSR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useEffect } from 'react'; | |
| import dynamic from 'next/dynamic'; | |
| ... | |
| let OwlCarousel; | |
| const MyComponent = () => { | |
| ... | |
| useEffect(() => { | |
| if (typeof(window) !== "undefined") OwlCarousel = dynamic(import('react-owl-carousel')); | |
| }, []); | |
| return ( | |
| ... | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment