beekai-oss / react-simple-img

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

Image not update when state changed #52

Closed stpwin closed 5 years ago

stpwin commented 5 years ago

<SimpleImg height={300} src={this.state.uploadedUrl} />

when this.state.uploadedUrl change image not updated.

bluebill1049 commented 5 years ago

when are you changing the src? image already in the viewport or hasn't intersected?

stpwin commented 5 years ago

when I called function

setState({
uploadedUrl: "IMAGE_URL"
});
bluebill1049 commented 5 years ago

so you want to change the image url after it's been lazy loaded?

if you change image url before been image been lazy loaded (hit intersection observer) that would work, but what's your case to change image after been lazy loaded? i don't get the use case here.

if you just want to change image by state, you should be ok with just normal img tag.

let me know your use case or code, we can work this out.

stpwin commented 5 years ago

Yes I do. I want to change src when I uploaded new profile picture.

bluebill1049 commented 5 years ago

how about this approach:

https://codesandbox.io/s/6z3lx27p5z

stpwin commented 5 years ago

Thank you!

juanpablocs commented 4 years ago

please update codesandbox link, error 404.

i have same problem of image...

does not update the image when i change the props from my component