Skip to content

Instantly share code, notes, and snippets.

@ciel334288
Last active December 31, 2020 09:26
Show Gist options
  • Select an option

  • Save ciel334288/f18ae272c14b5303da8506b9c91ab536 to your computer and use it in GitHub Desktop.

Select an option

Save ciel334288/f18ae272c14b5303da8506b9c91ab536 to your computer and use it in GitHub Desktop.
handle window object load for Nextjs/SSR
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