
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
react-image-loading
Advanced tools
Load an image in React with loading placeholder and fallback, with maximum customizability.
npm i react-image-loading
This will render the out of the box implementation of the ImageLoading component, including a loading placeholder and fallback that have absolute positioning to fill the dimensions of the parent container. See below on how to implement custom rendering and behavior.
import { Img } from 'react-image-loading';
const MyComponent = props =>
<div style={{minHeight: 150, position: 'relative'}}>
<Img src={props.src} srcSet={props.srcSet} />
</div>
The out of the box Img provides a basic use case for loading images with a loading placeholder and fallback. To customize you can implement your own version of the Img component specific to your project needs. Below is an example that mimics the basic behavior of the provided Img component, but changes the color of the Fallback and LoadingPlaceholder:
import * as React from 'react';
import ImageLoading, { Fallback, LoadingPlaceholder } from 'react-image-loading';
const Img = (props) => (
<ImageLoading>
{(ref, status) => (
<React.Fragment>
{status === 'error' || !props.src
? <Fallback style={{ backgroundColor: 'red'}} />
: <React.Fragment>
<img ref={ref} {...props} />
<LoadingPlaceholder
style={{
transition: 'opacity 0.5s',
opacity: status === 'loading' ? 1 : 0,
backgroundColor: 'blue'
}}
animate={status === 'loading'}
/>
</React.Fragment>
}
</React.Fragment>
)}
</ImageLoading>
);
export default Img;
You can also choose to create your own implementations of the Fallback and LoadingPlaceholder, or implement an entirely different logic altogether. Note: rendering the image tag with the provided ref is what triggers the loading of the image.
<ImageLoading>
Props
children
RenderPropsFnRenderPropsFn
Type: Function
Params
Returns
React.ReactNode
Ref
Type: Function
Params
imageElement
HTMLImageElement | nullReturns
void
LoadState
The loading state of the image. Will always start at "loading", even before first render of the image, so it will immediately be put into loading state.
Type: 'loading' | 'complete' | 'error'
<LoadingPlaceholder>
Props
style
React.CSSProperties?animationStyle
React.CSSProperties?animationDuration
number? Loop duration in msanimate
boolean?<Fallback>
Props
style
React.CSSProperties?FAQs
Load an image in React with loading placeholder and fallback
The npm package react-image-loading receives a total of 61 weekly downloads. As such, react-image-loading popularity was classified as not popular.
We found that react-image-loading demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.