scaleflex / react-cloudimage-responsive

Cloudimage Responsive will smartly resize, compress and accelerate images across the World in your site for all devices. The plugin supports lazy loading technique with fancy animation on image load. Any questions or issues, please report to https://github.com/scaleflex/react-cloudimage-responsive/issues
MIT License
45 stars 15 forks source link

Allow unmounting the provider #18

Closed GregoryPotdevin closed 4 years ago

GregoryPotdevin commented 4 years ago

Due to lazy loading some components, we can't use a global provider for react-cloudimage-responsive are started wrapping a few lazy-loaded screens with the provider instead. We are currently getting a memory leak warning from react when the component unmounts, as the resize handler isn't removed here : https://github.com/scaleflex/react-cloudimage-responsive/blob/master/src/provider.js

For our own needs we just subclassed the provider and added a componentWillUnmount method to remove the event listener.

class UnloadableCloudimageProvider extends CloudimageProvider {
  componentWillUnmount() {
    window.removeEventListener('resize', this.updateDimensions);
  }
}

This should probably be integrated natively into the library.

dzmitry-stramavus commented 4 years ago

@GregoryPotdevin hey, thx for posting the issue. We will update in next release

dzmitry-stramavus commented 4 years ago

done in v3.3.2