Migration from react-lazy-load-image-component
Move to lazymage. Change the imports and keep your code.
lazymage has the same API as react-lazy-load-image-component. It has the same components, props, and CSS classes.
Change the imports
- Install lazymage and remove the old package.
- Change the component imports.
- Change the effect CSS imports.
- import { LazyLoadImage } from "react-lazy-load-image-component";
- import "react-lazy-load-image-component/src/effects/blur.css";
+ import { LazyLoadImage } from "lazymage";
+ import "lazymage/effects/blur.css";
LazyLoadImage, LazyLoadComponent, and trackWindowScroll have the same names.
Behavior differences
- React 19 only. lazymage needs
reactandreact-dom19 or newer. - No runtime dependencies. lazymage does not use
lodashorprop-types. - New
data-stateattribute. The<img>and the wrapper show the load state. See Load states. - A new
srcresets the state. The state goes back toloading, the effect plays again, andonLoadandafterLoadrun again for the new image. - Images loaded before hydration. The state becomes
loaded, the wrapper gets thelazy-load-image-loadedclass, andonReadyruns.onLoadandafterLoaddo not run, because noloadevent reaches React. trackWindowScrolluses a ref. It finds the scroll container through therefthat it gives to your component, not throughfindDOMNode. Without an attached ref, it tracks the window. See Scroll containers.
New features
You can use these features after the migration. They are optional.
fallbackSrc,onReady,preload,root, andscrollMarginprops. See LazyLoadImage.- The
useLazyLoadanduseImageStatushooks. See Hooks. - The effects turn off their transitions when the user prefers reduced motion.