Skip to content
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

Documentation how to use this libary with React & co. #187

Closed
sapkra opened this issue Mar 9, 2018 · 21 comments
Closed

Documentation how to use this libary with React & co. #187

sapkra opened this issue Mar 9, 2018 · 21 comments

Comments

@sapkra
Copy link

sapkra commented Mar 9, 2018

In the readme file you tell me that I can use this library with React and other javascript frameworks but there is no documentation for it.

Would be nice if you can add example code. ;)

@verlok
Copy link
Owner

verlok commented Mar 10, 2018

You’re right, but I never tried it with any library yet.

Did anyone try it already?

@sapkra
Copy link
Author

sapkra commented Mar 10, 2018

I'm trying it at the moment with React. I will finish my implementation next week. If I still have time I can report how I implemented it.

@verlok
Copy link
Owner

verlok commented Mar 12, 2018

Please do. I would report the documentation in the main Readme file. It would be really useful to all the React community.

@MicroBenz
Copy link

Any updates?

@verlok
Copy link
Owner

verlok commented Jul 25, 2018

@sapkra did you make it?

@sapkra
Copy link
Author

sapkra commented Jul 25, 2018

Sorry for my late answer but I had to pause my work because of priority reasons. We continued to work on it this week.

I did it but I didn't had the time to post my results. I will set it on my todo list.

@verlok
Copy link
Owner

verlok commented Jul 26, 2018

Thank you very much.
Me and all the react community are looking forward to reading your feedback.

@xuya227939
Copy link

Do you have a document on the use of React?

@verlok
Copy link
Owner

verlok commented Aug 7, 2018

I'm asking for the support of the community here. I've never tried this on React.
@sapkra any news on your side?

@sapkra
Copy link
Author

sapkra commented Aug 7, 2018

I wrote it some time ago. Maybe there is potential for improvements. Please feel free to comment.

import PropTypes from 'prop-types';
import React from 'react';
import LazyLoad from 'vanilla-lazyload';
import lazyloadConfig from 'config/lazyload';

// Only initialize it one time for the entire application
if (!document.lazyLoadInstance) {
    document.lazyLoadInstance = new LazyLoad(lazyloadConfig);
}

export class Image extends React.Component {
// Update lazyLoad after first rendering of every image
    componentDidMount () {
        document.lazyLoadInstance.update();
    }

// Update lazyLoad after rerendering of every image
    componentDidUpdate () {
        document.lazyLoadInstance.update();
    }

// Just render the image with data-src
    render () {
        const {
            altText,
            source,
        } = this.props;

        return (
            <img
                alt={altText}
                className="rd__img"
                data-src={source}
            />
        );
    }
}

export default Image;

@verlok
Copy link
Owner

verlok commented Aug 7, 2018

Very good job @sapkra!
And thank you very much for helping out!

@xuya227939
Copy link

Thank you very much

@verlok verlok removed the Help Wanted label Aug 7, 2018
@xuya227939
Copy link

image
image
When I tried to run the code, I returned an empty object.

@verlok
Copy link
Owner

verlok commented Aug 7, 2018

@xuya227939 I'm investingating on this on issue #230.
Versions 10.12.0 and 8.12.0 should work correctly. Please use those until I fix that.

@verlok verlok closed this as completed Aug 7, 2018
@verlok verlok reopened this Aug 7, 2018
@verlok
Copy link
Owner

verlok commented Aug 7, 2018

Hey there, I'm reopening this because I need more information. How are you building your resources? It seems @xuya227939 you're using WebPack and UglifyJS. Is there any project / scaffolding from where I can copy your infrastructure to rapidly test LazyLoad in it?

@xuya227939
Copy link

Hey,The 8.12.0 version is good,I'm using the local database, so I'm sorry I can't provide the project.

@verlok
Copy link
Owner

verlok commented Aug 8, 2018

You're right.
Since 8.13.0 and 10.13.0 I changed the module formats (AMD, UMD, ES2015 and IIFE) in the dist folder.
This thread is now not anymore related to React usage, but to WebPack bundling.
I'm investigating this in #230 see details there.

@verlok
Copy link
Owner

verlok commented Aug 8, 2018

Duplicate of #230

@verlok verlok marked this as a duplicate of #230 Aug 8, 2018
@verlok
Copy link
Owner

verlok commented Aug 17, 2018

Hi everyone,

@sapkra, @luisherranz, I created a new example of usage here on Sandbox.

This implementation takes the same props that you would normally pass to the img tag.
Feel free to fork and improve!

Have a nice week-end,
Andrea

@luisherranz
Copy link

Thanks @verlok!

@verlok
Copy link
Owner

verlok commented Aug 19, 2018

You’re welcome guys! :)

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

No branches or pull requests

5 participants