$ yarn add axios
import axios from 'axios';
...
const getMovies = useCallback(async () => {
setLoading(true);
try {
const response = await axios.get(movieApi);
setMovies(response.data.data.movies);
} catch (e) {
console.log(e);
}
setLoading(false);
}, [movieApi]);
useEffect(() => {
getMovies();
}, [getMovies]);
import axios from 'axios';
...
const getMovie = useCallback(async () => {
setLoading(true);
// const json = await (
// await fetch(`https://yts.mx/api/v2/movie_details.json?movie_id=${id}`)
// ).json();
try {
const response = await axios.get(
`https://yts.mx/api/v2/movie_details.json?movie_id=${id}`
);
console.log(response);
setMovie(response.data.data.movie);
} catch (e) {
console.log(e);
}
setLoading(false);
}, [id]);
useEffect(() => {
getMovie();
}, [getMovie]);
import axios from 'axios';
...
const getMovies = useCallback(async () => {
setLoading(true);
try {
const response = await axios.get(
`https://yts.mx/api/v2/list_movies.json?page=${page}&${group}&sort_by=rating`
);
setMovies(response.data.data.movies);
} catch (e) {
console.log(e);
}
setLoading(false);
}, [group, page]);
useEffect(() => {
getMovies();
return;
}, [getMovies]); // group이나 page 바뀔때마다
Home.module.css
...
/* 반응형 */
@media screen and (max-width: 600px) {
.container::after {
content: 'please watch on Desktop! 🖥';
background-color: rgba(255, 255, 255, 0.8);
padding: 60px;
border-radius: 10px;
display: block;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 40px;
text-align: center;
}
}
- 모바일 ver 추가 (슬라이드 - 터치 이벤트 구현)
- search 컴포넌트 추가