forked from namastedev/namaste-frontend-system-design
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
374d66d
commit db862a0
Showing
5 changed files
with
62 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
import Body from "./components/Body"; | ||
|
||
function App() { | ||
return <div className="text-2xl font-bold">Hello World</div>; | ||
return ( | ||
<div> | ||
<div className="text-2xl font-bold">Hello World</div> | ||
<Body /> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
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,28 @@ | ||
import { useEffect, useState } from "react"; | ||
import { MemeCard } from "./MemeCard"; | ||
import Shimmer from "./Shimmer"; | ||
|
||
const Body = () => { | ||
const [memes, setMemes] = useState(null); | ||
|
||
useEffect(() => { | ||
fetchMemes(); | ||
}, []); | ||
|
||
const fetchMemes = async () => { | ||
const data = await fetch("https://meme-api.com/gimme/20"); | ||
const json = await data.json(); | ||
setMemes(json.memes); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-wrap"> | ||
{!memes ? ( | ||
<Shimmer /> | ||
) : ( | ||
memes.map((meme, i) => <MemeCard key={i} data={meme} />) | ||
)} | ||
</div> | ||
); | ||
}; | ||
export default Body; |
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,10 @@ | ||
export const MemeCard = ({ data }) => { | ||
const { url, title, author } = data; | ||
|
||
return ( | ||
<div className="p-5 m-5 border border-black rounded-lg"> | ||
<img className="w-64 h-64" alt="meme" src={url} /> | ||
<p>{author}</p> | ||
</div> | ||
); | ||
}; |
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,10 @@ | ||
const Shimmer = () => { | ||
return Array(15) | ||
.fill(0) | ||
.map((n, i) => ( | ||
<div key={i} className="p-5 m-5 border border-black rounded-lg"> | ||
<div className="w-64 h-64 bg-gray-200"></div> | ||
</div> | ||
)); | ||
}; | ||
export default Shimmer; |
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