Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@lironefitoussi/react-skeleton-img-loader
Advanced tools
A React hook for lazy loading images with MUI Skeleton integration
A React hook for lazy loading images with an integrated Material-UI skeleton loader.
npm install react-skeleton-img-loader @mui/material
Ensure you have the peer dependencies installed:
npm install react @mui/material @emotion/react @emotion/styled
import React from 'react';
import useLazyImage from 'react-skeleton-img-loader';
const MyComponent = () => {
const lazyImage = useLazyImage('https://example.com/image.jpg', {
width: 300,
height: 200,
alt: 'Example image',
});
return (
<div>
<h1>My Lazy Loaded Image</h1>
{lazyImage}
</div>
);
};
export default MyComponent;
useLazyImage(src, options)
A hook that returns a React element containing a lazy-loaded image with a skeleton loader.
src
(string): The source URL of the image to be loaded.options
(object):
width
(number): The width of the image and skeleton.height
(number): The height of the image and skeleton.alt
(string, optional): The alt text for the image. Default: ''....imgProps
(object, optional): Any additional props to be passed to the img element.(React.ReactElement): A div containing both the skeleton and the image.
const MyComponent = () => {
const lazyImage = useLazyImage('https://example.com/image.jpg', {
width: 300,
height: 200,
alt: 'A beautiful landscape',
});
return <div>{lazyImage}</div>;
};
const MyComponent = () => {
const lazyImage = useLazyImage('https://example.com/image.jpg', {
width: 300,
height: 200,
alt: 'A beautiful landscape',
className: 'my-image-class',
style: { borderRadius: '8px' },
});
return <div>{lazyImage}</div>;
};
The useLazyImage
hook includes TypeScript definitions. Here's an example of how to use it with TypeScript:
import React from 'react';
import useLazyImage from 'react-skeleton-img-loader';
interface MyComponentProps {
imageSrc: string;
}
const MyComponent: React.FC<MyComponentProps> = ({ imageSrc }) => {
const lazyImage = useLazyImage(imageSrc, {
width: 300,
height: 200,
alt: 'Example image',
});
return (
<div>
<h1>My Lazy Loaded Image</h1>
{lazyImage}
</div>
);
};
export default MyComponent;
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)Distributed under the MIT License. See LICENSE
for more information.
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
FAQs
A React hook for lazy loading images with MUI Skeleton integration
We found that @lironefitoussi/react-skeleton-img-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.