File tree Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change 1
1
import { useEffect , useState } from "react" ;
2
2
import Seo from "../components/Seo" ;
3
3
4
- export default function Home ( ) {
5
- const [ movies , setMovies ] = useState ( ) ;
6
- useEffect ( ( ) => {
7
- ( async ( ) => {
8
- const { results } = await ( await fetch ( `/api/movies` ) ) . json ( ) ;
9
- setMovies ( results ) ;
10
- } ) ( ) ;
11
- } , [ ] ) ;
4
+ export default function Home ( { results } ) {
12
5
return (
13
6
< div className = "container" >
14
7
< Seo title = "Home" />
15
- { ! movies && < h4 > Loading...</ h4 > }
16
- { movies ?. map ( ( movie ) => (
8
+ { results ?. map ( ( movie ) => (
17
9
< div className = "movie" key = { movie . id } >
18
10
< img src = { `https://image.tmdb.org/t/p/w500/${ movie . poster_path } ` } />
19
11
< h4 > { movie . original_title } </ h4 >
@@ -43,3 +35,14 @@ export default function Home() {
43
35
</ div >
44
36
) ;
45
37
}
38
+
39
+ export async function getServerSideProps ( ) {
40
+ const { results } = await (
41
+ await fetch ( `http://localhost:3000/api/movies` )
42
+ ) . json ( ) ;
43
+ return {
44
+ props : {
45
+ results,
46
+ } ,
47
+ } ;
48
+ }
You can’t perform that action at this time.
0 commit comments