Skip to content

Instantly share code, notes, and snippets.

@codebucks27
Created January 9, 2021 10:38
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/c173c40b93fdb4e48269c00cdeeec9d8 to your computer and use it in GitHub Desktop.
Save codebucks27/c173c40b93fdb4e48269c00cdeeec9d8 to your computer and use it in GitHub Desktop.
import React, { useEffect, useState } from "react";
import ReactLoading from "react-loading";
function PreLoader1() {
const [data, setData] = useState([]);
const [done, setDone] = useState(undefined);
useEffect(() => {
setTimeout(() => {
fetch("https://jsonplaceholder.typicode.com/posts")
.then((response) => response.json())
.then((json) => {
console.log(json);
setData(json);
setDone(true);
});
}, 2000);
}, []);
return (
<>
{!done ? (
<ReactLoading
type={"bars"}
color={"#03fc4e"}
height={100}
width={100}
/>
) : (
<ul>
{data.map((post) => (
<li key={post.id}>{post.title}</li>
))}
</ul>
)}
</>
);
}
export default PreLoader1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment