beekai-oss / react-simple-img

🌅 React lazy load images with IntersectionObserver API and Priority Hints
MIT License
989 stars 41 forks source link

[Request] How about adding `event hook` to SimpleImg element? #46

Closed JaeYeopHan closed 5 years ago

JaeYeopHan commented 5 years ago

Description

like this:

<SimpleImg
  height={500}
  placeholder="linear-gradient(rgb(30, 87, 153) 0%, rgb(125, 185, 232) 100%)"
  src="your image path"
  // event listener
  on={() => console.log('image visible')}
  once={() => console.log('image loaded')}
/>

Why?

If need to restore scroll, have to know timing that image loaded.

Reference

bluebill1049 commented 5 years ago

hey @JaeYeopHan,

Yes can be done, probably will be the next minor update. I am working on one of the issue at the moment.

is onComplete hook enough?

cheers bill

JaeYeopHan commented 5 years ago

onComplete is awesome! Thanks!

bluebill1049 commented 5 years ago

👍 will try to work this over the weekend

bluebill1049 commented 5 years ago

want to try this beta version and test?

react-simple-img@2.0.0-beta.2

onComplete is the prop name

bluebill1049 commented 5 years ago

The have been baked in the latest release, with onComplete props. feel free to re-open if you found issue.