Skip to content

Instantly share code, notes, and snippets.

@0kzh
Last active August 7, 2021 19:31
Show Gist options
  • Save 0kzh/acc278e7b18a001393f5c059bd317971 to your computer and use it in GitHub Desktop.
Save 0kzh/acc278e7b18a001393f5c059bd317971 to your computer and use it in GitHub Desktop.
Code to render a Lottie animation using React (with Lazy Loading)
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