forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(client): remove react lazy loader library (freeCodeCamp#49468)
* feat(client): remove react lazy loader library * fix: use loading='lazy' to defer loading
- Loading branch information
Muhammed Mustafa
authored
Feb 22, 2023
1 parent
1d8de86
commit 0971b6a
Showing
8 changed files
with
50 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import './image-loader.css'; | ||
|
||
interface LazyImageProps { | ||
alt?: string; | ||
className?: string; | ||
height?: number; | ||
loadedClassName?: string; | ||
loadingClassName?: string; | ||
offsetVertical?: number; | ||
src?: string; | ||
style?: React.CSSProperties; | ||
width?: number; | ||
} | ||
|
||
const LazyImage = ({ | ||
className = '', | ||
loadedClassName = 'img-loaded', | ||
loadingClassName = 'img-loading', | ||
alt, | ||
src, | ||
style | ||
}: LazyImageProps): JSX.Element => { | ||
const [loaded, setLoaded] = useState(false); | ||
const fullClassName = `${className} ${ | ||
loaded ? loadedClassName : loadingClassName | ||
}`; | ||
return ( | ||
<img | ||
alt={alt} | ||
className={fullClassName} | ||
onLoad={() => setLoaded(true)} | ||
src={src} | ||
style={style} | ||
loading='lazy' | ||
/> | ||
); | ||
}; | ||
|
||
export default LazyImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.