react-lazyload icon indicating copy to clipboard operation
react-lazyload copied to clipboard

SSR support

Open Saeeed-B opened this issue 3 years ago • 2 comments

@ameerthehacker This package does not appear to support ssr. Photos are not displayed in the viewport.

Saeeed-B avatar Feb 22 '22 12:02 Saeeed-B

No more features are actively developed but I'm happy to accept a PR if you wish to contribute

ameerthehacker avatar Feb 22 '22 15:02 ameerthehacker

@Saeeed-B

  /**
   * https://github.com/alex-cory/use-ssr
   * https://github.com/alex-cory/use-ssr/blob/master/useSSR.ts
   */
  const isBrowser: boolean = !!(
    typeof window !== 'undefined' &&
    window.document &&
    window.document.createElement
  );
  
  const Lazy = ({ children }) => {
    if (lazy && isBrowser) {
      return (
        <LazyLoad
          className={classes.avatar}
          once
          placeholder={<LoadingSpinner />}
        >
          {{children}}
        </LazyLoad>
      );
    } else {
      return children;
    }
  }

prmichaelsen avatar Jul 24 '22 11:07 prmichaelsen