-
Notifications
You must be signed in to change notification settings - Fork 166
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
Placeholder images #82
Comments
Not sure if there's an official solution, but in my project we literally have text "under" the image element, such that when it's not loaded you can see the text :) |
Why not just wrap a loader in it as well?
The loader component would display something else when not loaded something like the following,
Regardless this doesn't seem something that the LazyLoad component should handle. Unless people disagree. There is a PR to have a placeholder prop as well. Interested in thoughts. |
Look! Not just me who want to have this feature. ^_^ |
#81 - just for reference as there is some discussion there too. |
@loktar00 In your example, how can the LazyLoad component tell the wrapper when the image is loaded and thus change the this.props.loaded from false to true? |
My solution, if somebody still interested import React, { useState, useCallback } from 'react';
import LazyLoad from 'react-lazy-load';
export default function LazyWithPlaceholder({
placeholder,
children,
...forwardingProps
}) {
const [loaded, setLoaded] = useState(false);
const handleVisible = useCallback(() => setLoaded(true), []);
return (
<>
{!loaded && placeholder}
<LazyLoad {...forwardingProps} onContentVisible={handleVisible}>
{children}
</LazyLoad>
</>
);
} |
I'll add this as an example for the |
Is their a way we can keep a placeholder(text / image / gif) before the element appears on DOM
Ex: We have few set of images in list and we have to display a loader before the image appears.
The text was updated successfully, but these errors were encountered: