Gathering detailed insights and metrics for loadable-image
Gathering detailed insights and metrics for loadable-image
Gathering detailed insights and metrics for loadable-image
Gathering detailed insights and metrics for loadable-image
React Component to lazy load images. With smooth transition between loading states
npm install loadable-image
Typescript
Module System
Node Version
NPM Version
TypeScript (70.59%)
JavaScript (22.95%)
HTML (3.63%)
Shell (2.83%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
32 Stars
91 Commits
2 Forks
1 Watchers
2 Branches
1 Contributors
Updated on Jun 23, 2025
Latest Version
3.3.0
Package Id
loadable-image@3.3.0
Unpacked Size
18.37 kB
Size
5.22 kB
File Count
13
NPM Version
10.9.2
Node Version
22.13.1
Published on
Mar 02, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
17
React Component to lazy load images.
npm i loadable-image
Or via yarn
yarn add loadable-image
<AsyncImage />
accepts all props of <img />
tag.
1import { AsyncImage } from 'loadable-image' 2... 3<AsyncImage 4 src='https://picsum.photos/1900' 5 style={{ width: 150, height: 150 }} 6/>
Loader
/Error
You can pass your own loader
and error
components as props to AsyncImage
component.
1import { AsyncImage } from 'loadable-image' 2... 3<AsyncImage 4 src='https://picsum.photos/1900' 5 style={{ width: 150, height: 150 }} 6 loader={<div style={{ background: '#888' }}/>} 7 error={<div style={{ background: '#eee' }}/>} 8/>
Since under the hood <AsyncImage />
is just a picture
element. You can pass an array of different Sources
as a prop. And browser will pick the first one that it supports.
1import { AsyncImage } from 'loadable-image' 2... 3<AsyncImage 4 src="./image.jpg" 5 sources={[ 6 { type:"image/avif", srcSet:"./image.avif" }, 7 { type:"image/webp", srcSet:"./image.webp" } 8 ]} 9 style={{ width: 200, height: 200 }} 10/>
To make image responsive you can use aspectRatio
property in style
prop. This way you can specify only width
or height
as 100%
and the other one as auto
.
Note that if you support older browsers you might need to use aspectRatio
padding-hack.
1import { AsyncImage } from 'loadable-image' 2... 3<AsyncImage 4 src='https://picsum.photos/1900' 5 style={{ width: "100%", height: "auto", aspectRatio: 16 / 9 }} 6/>
Under the hood AsyncImage
uses transitions-kit library
it's a collection Transition components built on top of react-transition-group its a small library maintained by React team for animating between different views.
You can pass your own Transition
as a prop to AsyncImage
component.
Here’s how you can implement a Blur
transition that replaces a low-resolution image
with a high-resolution
one
1import { Blur } from 'transitions-kit' 2import { AsyncImage } from 'loadable-image' 3... 4<AsyncImage 5 src='./original-image.jpg' 6 style={{ width: 150, height: 150 }} 7 Transition={props => <Blur radius={10} {...props}/>} 8 loader={<img src='./extra-small-1x1.jpg' />} 9/>
By default AsyncImage
uses Fade
transition.
1import { Fade } from 'transitions-kit' 2import { AsyncImage } from 'loadable-image' 3... 4<AsyncImage 5 src='https://picsum.photos/1900' 6 style={{ width: 150, height: 150 }} 7 loader={<div style={{ background: '#888' }}/>} 8 Transition={Fade} 9/>
There are plenty different already predefined Transition components such as Grow
, Zoom
, Slide
, Blur
, Fade
etc. in transitions-kit.
Feel free to try any of them.
1import { Grow } from 'transitions-kit' 2import { AsyncImage } from 'loadable-image' 3... 4<AsyncImage 5 src='https://picsum.photos/1900' 6 style={{ width: 150, height: 150 }} 7 loader={<div style={{ background: '#888' }}/>} 8 Transition={Grow} 9/>
<AsyncImage />
accepts all standard props for HtmlImageElement
and the following:
Property | Type | Description |
---|---|---|
className | String | NOTE: CSS from style object has a higher priority |
style | CSSProperties | CSSStyleDeclaration object |
rootMargin | string by default: '600px 0px' | Margin around the root. Specifies when to trigger an image download. |
loader | ReactElement | React element to display a loading state. |
error | ReactElement | React element to display an error state. |
sources | Array<SourceProps> | An array of options for <source /> element. |
timeout | Number or Object | The duration for the transition, in milliseconds. You may specify a single timeout for all transitions, or individually with an object. |
Transition | ComponentType<TransitionProps> | Custom Transition component. Check out transitions-kit's predefined components |
No vulnerabilities found.
No security vulnerabilities found.