Skip to content

Commit c27afcd

Browse files
2.1 Fetching Data
1 parent 33c1f4d commit c27afcd

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

components/NavBar.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,41 @@ export default function NavBar() {
55
const router = useRouter();
66
return (
77
<nav>
8-
<Link href="/">
9-
<a className={router.pathname === "/" ? "active" : ""}>Home</a>
10-
</Link>
11-
<Link href="/about">
12-
<a className={router.pathname === "/about" ? "active" : ""}>About</a>
13-
</Link>
8+
<img src="/vercel.svg" />
9+
<div>
10+
<Link href="/">
11+
<a className={router.pathname === "/" ? "active" : ""}>Home</a>
12+
</Link>
13+
<Link href="/about">
14+
<a className={router.pathname === "/about" ? "active" : ""}>About</a>
15+
</Link>
16+
</div>
1417
<style jsx>{`
15-
a {
16-
text-decoration: none;
18+
nav {
19+
display: flex;
20+
gap: 10px;
21+
flex-direction: column;
22+
align-items: center;
23+
padding-top: 20px;
24+
padding-bottom: 10px;
25+
box-shadow: rgba(50, 50, 93, 0.25) 0px 50px 100px -20px,
26+
rgba(0, 0, 0, 0.3) 0px 30px 60px -30px;
27+
}
28+
img {
29+
max-width: 100px;
30+
margin-bottom: 5px;
31+
}
32+
nav a {
33+
font-weight: 600;
34+
font-size: 18px;
1735
}
1836
.active {
1937
color: tomato;
2038
}
39+
nav div {
40+
display: flex;
41+
gap: 10px;
42+
}
2143
`}</style>
2244
</nav>
2345
);

pages/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1+
import { useEffect, useState } from "react";
12
import Seo from "../components/Seo";
23

4+
const API_KEY = "10923b261ba94d897ac6b81148314a3f";
5+
36
export default function Home() {
7+
const [movies, setMovies] = useState();
8+
useEffect(() => {
9+
(async () => {
10+
const { results } = await (
11+
await fetch(
12+
`https://api.themoviedb.org/3/movie/popular?api_key=${API_KEY}`
13+
)
14+
).json();
15+
setMovies(results);
16+
})();
17+
}, []);
418
return (
519
<div>
620
<Seo title="Home" />
7-
<h1 className="active">Hello</h1>
21+
{!movies && <h4>Loading...</h4>}
22+
{movies?.map((movie) => (
23+
<div key={movie.id}>
24+
<h4>{movie.original_title}</h4>
25+
</div>
26+
))}
827
</div>
928
);
1029
}

styles/globals.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ body {
66
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
77
}
88

9+
body {
10+
max-width: 520px;
11+
width: 100%;
12+
margin: 0 auto;
13+
}
14+
915
a {
1016
color: inherit;
1117
text-decoration: none;

0 commit comments

Comments
 (0)