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
62.3
Supply Chain
93.1
Quality
80
Maintenance
100
Vulnerability
100
License
TypeScript (70.69%)
JavaScript (22.84%)
HTML (3.64%)
Shell (2.83%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
61,832
Last Day
170
Last Week
1,263
Last Month
4,793
Last Year
46,691
29 Stars
89 Commits
1 Forks
2 Watchers
2 Branches
1 Contributors
Updated on Jan 23, 2025
Minified
Minified + Gzipped
Latest Version
3.2.6
Package Id
loadable-image@3.2.6
Unpacked Size
18.71 kB
Size
5.28 kB
File Count
13
NPM Version
10.5.1
Node Version
22.0.0
Published on
Jul 27, 2024
Cumulative downloads
Total Downloads
Last Day
-23.8%
170
Compared to previous day
Last Week
-4%
1,263
Compared to previous week
Last Month
28.8%
4,793
Compared to previous month
Last Year
270.2%
46,691
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.