react-imaggine
⚠️ Library is in an early stage of development and is far from being production-ready.
Features
- load image using low quality placeholder (LQIP)
- lazy load images only once they enter viewport
- easy to extend by using exported hooks
Components
These are top-level abstractions that aim to minimize the API surface of the library. If you need more control over what is rendered, consider using hooks.
ReactImaggine
Load image using LQIP. Use ReactImaggineLazy
to load image once it enters viewport.
Props
src
(String) - path to an imageplaceholder
(String) - path to a placeholderprefetch
(Boolean) - prefetch image onrequestIdleCallback
- other props are passed to HTML
<img>
element
Example
import ReactImaggine ReactImaggineLazy from 'react-imaggine'; const MyComponent => <> <AboveTheFold> <ReactImaggine ="/assets/image.jpg" ="/assets/placeholder.jpg" ="image" /> </AboveTheFold> <BelowTheFold> <ReactImaggineLazy ="/assets/image-2.jpg" ="/assets/placeholder-2.jpg" ="image" /> </BelowTheFold> </>;
useLQIP
Controls image state - initial state is placeholder
which then automatically updates to src
.
Parameters
placeholder
(String) - path to a placeholdersrc
(String) - path to an imageloadingOptions
(Object)prefetch
(Boolean) - prefetch image onrequestIdleCallback
load
(Boolean) - when explicitly set to false, it prevents state update
Example
const Image = { const src = ; return <img src=src />;};
useLQIPLazy
- lazy load image using LQIP
Does the same as useLQIP
except it updates image state only once it enters viewport.
Parameters
placeholder
(String) - path to a placeholdersrc
(String) - path to an imageloadingOptions
(Object)prefetch
(Boolean) - prefetch image onrequestIdleCallback
Example
const Image = { const src ref = ; return <img src=src ref=ref />;};