41 | );
42 | }
43 |
44 | export default Home;
45 |
--------------------------------------------------------------------------------
/public/vite.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Lazyload Images
2 |
3 | This tutorial is meant to showcase how to lazyload images in a react application using the NPM library: [React Lazy Load Image Component](https://www.npmjs.com/package/react-lazy-load-image-component)
4 |
5 | ### Default
6 |
7 | Default image in react without the lazyload effect
8 | [Source](https://react-lazyload-image.netlify.app/default)
9 |
10 | ```js
11 | import Image from "../images/bird.jpg";
12 | ;
13 | ```
14 |
15 | ### Placeholder
16 |
17 | This illustrates the lazyload image component with a placeholder image.
18 | To test this, visit the [/placeholder](https://react-lazyload-image.netlify.app/default) page, set throttling in developer tools to Good 2G, and refresh the page to see the effect.
19 |
20 | Adding a placeholder image is very simple, simply add `placeholderSrc=""` attribute with your placeholder image within the quotes to the `LazyLoadImage` component.
21 |
22 | ```js
23 | import { LazyLoadImage } from "react-lazy-load-image-component";
24 | import Image from "../images/bird.jpg";
25 | import PlaceholderImage from "../images/placeholder.jpg";
26 |
27 | ;
34 | ```
35 |
36 | ### Blur
37 |
38 | This illustrates the lazyload image component with a placeholder image and a blur effeect.
39 | To test this, visit the [/blur](https://react-lazyload-image.netlify.app/default) p
40 |
41 | Combining the placeholder image and blur effect provides the best experience for users. To enable it, add the placeholder image and add and effect set to `blur`.
42 |
43 | You can add effects like:
44 |
45 | - blur: renders a blurred image based on placeholderSrc and transitions to a non-blurred one when the image specified in the src is loaded.
46 | - black-and-white: renders a black and white image based on placeholderSrc and transitions to a colorful image when the image specified in the src is loaded.
47 | - opacity: renders a blank space and transitions to full opacity when the image is loaded.
48 |
49 | > Note: They effects rely on CSS and the corresponding CSS file must be imported:
50 |
51 | ```js
52 | import { LazyLoadImage } from "react-lazy-load-image-component";
53 | import Image from "../images/bird.jpg";
54 | import PlaceholderImage from "../images/placeholder.jpg";
55 |
56 | ;
64 | ```
65 |
66 | Tutorial prepared by [Victor Eke](https://github.com/evavic44)
67 |
68 | ## Resources
69 |
70 | - [Demo URL](https://react-lazyload-image.netlify.app/)
71 | - [React Lazy Load Image Component - NPM](https://www.npmjs.com/package/react-lazy-load-image-component)
72 | - [React Lazy Load Image Component - GitHub](https://github.com/Aljullu/react-lazy-load-image-component)
73 |
--------------------------------------------------------------------------------