react-lazy-load-image-component icon indicating copy to clipboard operation
react-lazy-load-image-component copied to clipboard

Is there any way to do server side render ?

Open krishnaTORQUE opened this issue 4 years ago • 2 comments

Describe the solution you'd like Server Side Rending. Send IMG tag directly to client

krishnaTORQUE avatar Dec 27 '19 12:12 krishnaTORQUE

I'd do a PR, but I'm not sure this is the most optimal place to put the noscript.

  1. Clone the repo
  2. Open LazyLoadImage.jsx
  3. Replace this with the below code.
return (
      <>
        <LazyLoadComponent
          beforeLoad={beforeLoad}
          className={className}
          delayMethod={delayMethod}
          delayTime={delayTime}
          height={height}
          placeholder={placeholder}
          scrollPosition={scrollPosition}
          style={style}
          threshold={threshold}
          useIntersectionObserver={useIntersectionObserver}
          visibleByDefault={visibleByDefault}
          width={width}
        >
          {this.getImg()}
        </LazyLoadComponent>
        <noscript>{this.getImg()}</noscript>
      </>
    );
  1. Profit

Profit

vhpoet avatar Mar 03 '20 06:03 vhpoet

Actually, this is better.

LazyLoadImage.jsx

if (typeof window === "undefined") return <noscript>{this.getImg()}</noscript>;

return (
  <>
    <LazyLoadComponent
      beforeLoad={beforeLoad}
      className={className}
      delayMethod={delayMethod}
      delayTime={delayTime}
      height={height}
      placeholder={placeholder}
      scrollPosition={scrollPosition}
      style={style}
      threshold={threshold}
      useIntersectionObserver={useIntersectionObserver}
      visibleByDefault={visibleByDefault}
      width={width}
    >
      {this.getImg()}
    </LazyLoadComponent>
  </>
);

vhpoet avatar Jun 14 '20 06:06 vhpoet