$ npm i axios
API: https://yts-proxy.now.sh/list_movies.json
↪️ 출처
import React from "react";
import axios from "axios";
class App extends React.Component {
state = {
isLoading: true,
movies: []
}
getMovies = async () => {
const movies = await axios.get("https://yts-proxy.now.sh/list_movies.json");
}
componentDidMount () {
this.getMovies();
}
render() {
const {isLoading} = this.state;
return (
<div>
{isLoading ? "Loading..." : "We are Ready!"}
</div>
);
}
}
export default App;
getMovies = async () => {
const movies = await axios.get("https://yts-proxy.now.sh/list_movies.json");
}
getMovies
가 비동기(async)라는 것을 알려주고,
movies
는 axios가 데이터를 가져올 때까지 기다린다(await).