import React,{useEffect, useState} from 'react'
import { FaCode } from "react-icons/fa";
import {API_URL, IMAGE_BASE_URL, API_KEY} from '../../Config';
import MainImage from './Sections/MainImage'
import GridCards from '../common/GridCards'
import {Row} from 'antd';
function LandingPage() {
const [Movies, setMovies] = useState([]);
const [MainMovieImage, setMainMovieImage] = useState(null);
function hookFunction(Movies, MainMovieImage){
setMainMovieImage(MainMovieImage)
// setMainMovieImage(response.results[0])
setMovies([Movies.results])
console.log(`Movies-> ${Movies}`, `MainMovieImage-> ${MainMovieImage}`);
}
function MoviesCall(){
Movies.map((movie, index) => {
console.log(index);
})
}
useEffect(() => {
const endpoint = `${API_URL}movie/popular?api_key=${API_KEY}&language=en-US&page=1`;
fetch(endpoint)
.then(response => response.json())
.then(response =>{
hookFunction(response.results, response.results[0])
}
)
return () => {
console.log("I'm dying...");
}
}, [])
return (
<>
<div style={{width:'100%', margin:'0'}}>
{/* path오류는 값을 가져오기전 랜더링해버려서 그럼 */}
{/* MainImage */}
{MainMovieImage &&
<MainImage image={`${IMAGE_BASE_URL}w1280${MainMovieImage.backdrop_path}`}
title ={MainMovieImage.original_title}
text = {MainMovieImage.overview}
/>
}
<div style={{width:'100%', margin:'1rem auto'}}>
<h2>Movies by latest</h2>
<hr/>
{/* GridImage */}
<Row>
{Movies && Movies.map(function(movie, index){
console.log(`movie->>>${movie}`);
})}
</Row>
</div>
<div style={{ display:'flex', justifyContent:'center' }}>
<button>
Load More
</button>
</div>
</div>
</>
)
}
export default LandingPage
확인했는데요 렌더링부분에서 undefined가뜹니다.