Skip to content

Instantly share code, notes, and snippets.

@codebucks27
Last active January 30, 2023 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codebucks27/b09aa861ac0d34c36ab886c559b38af0 to your computer and use it in GitHub Desktop.
Save codebucks27/b09aa861ac0d34c36ab886c559b38af0 to your computer and use it in GitHub Desktop.
import React, { useEffect, useState } from "react";
import Lottie from "react-lottie";
import * as location from "../1055-world-locations.json";
import * as success from "../1127-success.json";
const defaultOptions1 = {
loop: true,
autoplay: true,
animationData: location.default,
rendererSettings: {
preserveAspectRatio: "xMidYMid slice",
},
};
const defaultOptions2 = {
loop: true,
autoplay: true,
animationData: success.default,
rendererSettings: {
preserveAspectRatio: "xMidYMid slice",
},
};
function PreLoader2() {
const [data, setData] = useState([]);
const [loading, setloading] = useState(undefined);
const [completed, setcompleted] = useState(undefined);
useEffect(() => {
setTimeout(() => {
fetch("https://jsonplaceholder.typicode.com/posts")
.then((response) => response.json())
.then((json) => {
console.log(json);
setData(json);
setloading(true);
setTimeout(() => {
setcompleted(true);
}, 1000);
});
}, 2000);
}, []);
return (
<>
{!completed ? (
<>
{!loading ? (
<Lottie options={defaultOptions1} height={200} width={200} />
) : (
<Lottie options={defaultOptions2} height={100} width={100} />
)}
</>
) : (
<>
<h1>Your Data</h1>
<br />
<h6 style={{ position: "Absolute", right: "5rem", bottom: "0" }}>
<a
style={{ color: "white" }}
href="https://lottiefiles.com/ijum4kzkmt"
>
Earth Animation by Hanina Kahfi on LottieFiles
</a>
<br />
<a style={{ color: "white" }} href="https://lottiefiles.com/darius">
Success Animation by Chris Gannon on LottieFiles
</a>
</h6>
</>
)}
</>
);
}
export default PreLoader2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment