Last active
August 7, 2021 19:31
-
-
Save 0kzh/acc278e7b18a001393f5c059bd317971 to your computer and use it in GitHub Desktop.
Code to render a Lottie animation using React (with Lazy Loading)
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
import animationData from "./loading.json"; | |
import placeholderImg from "./preview.png"; | |
import { Player } from "@lottiefiles/react-lottie-player"; | |
const App = () => { | |
return ( | |
<div className="App"> | |
{!animationData ? ( | |
<img src={placeholderImg} alt="Loading placeholder" /> | |
) : ( | |
<Player | |
autoplay | |
loop | |
src={animationData} | |
style={{ height: "50%", width: "50%" }} | |
/> | |
)} | |
</div> | |
); | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment