Skip to content

Updated code to be universal. So it can be executed in node environment. #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2018

Conversation

gihan9a
Copy link
Contributor

@gihan9a gihan9a commented Oct 3, 2018

This PR enables the image component to be executed on server side for SSR. Otherwise it throws following error.

ReferenceError: window is not defined
at new r (<path>/node_modules/react-lazy-load-image-component/build/index.js:1:7434)
...

Additionally we can use it with visibleByDefault option visibleByDefault={typeof window === "undefined"} to output image src tags from server rendered content.

@Aljullu Aljullu merged commit 814b3a5 into Aljullu:master Oct 7, 2018
@Aljullu
Copy link
Owner

Aljullu commented Oct 7, 2018

This looks good, thanks for working on this! 🎉

@Aljullu Aljullu self-requested a review October 7, 2018 11:31
@gihan9a
Copy link
Contributor Author

gihan9a commented Oct 7, 2018

Thank you for merging 👍

@petertenhoor
Copy link

Thanks for this issue. It solved my problem. Had to do the following to make my component work with server side rendering:

<LazyLoadImage className={styles.footerImage}
               effect="opacity"
               visibleByDefault={typeof window === "undefined"}
               src={require("../../images/super-cool-image.png")}
               alt="Super cool alt tag"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants