twobin / react-lazyload

Lazy load your component, image or anything matters the performance.
MIT License
5.86k stars 487 forks source link

Add API for either a `render` prop or renderprops #222

Open tstirrat15 opened 5 years ago

tstirrat15 commented 5 years ago

By conditionally rendering children, this library already-constructed instances of components and chooses whether to render them or not. This works for most use cases, but there are some libraries that do expensive or interesting work before mount. There's a discussion to be had about whether it's a good idea on the part of those libraries, but I want to take that as a given.

Adding a render prop that only executes if the lazyload conditions are met would sidestep this issue. It would also be slightly more efficient, again because the component instances wouldn't be created until the render function is executed.

Thoughts? I'm willing to do the work to add this feature.

ameerthehacker commented 5 years ago

@tstirrat15 sounds interesting can you please implement a MVP to demonstrate the advantage that you are talking about?

tstirrat15 commented 5 years ago

Sure thing! See the PR.