getMovies = async () => {
const {data: {data: {movies}}} =
await axios.get("https://yts-proxy.nomadcoders1.now.sh/list_movies.json");
this.setState({movies});
}
...
ES6의 console.log안에 있는 값과 ES5의 console.log안에 있는 값은 동일하다.
ES6
const {data: {data: {movies}}} =
await axios.get("https://yts-proxy.nomadcoders1.now.sh/list_movies.json");
console.log(movies);
ES5
const movies =
await axios.get("https://yts-proxy.nomadcoders1.now.sh/list_movies.json");
console.log(movies.data.data.movies);
setState를 이용할 때, key와 변수명이 같은 경우 한번만 사용해도 된다.
ES6
this.setState({movies: movies})
ES5
this.setState({movies})
import React from 'react';
import './App.css';
//eslint-disable-next-line
import PropTypes from "prop-types";
import axios from "axios";
class App extends React.Component{
state = {
isLoading: true,
moives: []
}
getMovies = async () => {
const {data: {data: {movies}}} = await axios.get("https://yts-proxy.nomadcoders1.now.sh/list_movies.json");
this.setState({movies})
}
componentDidMount(){
this.getMovies();
}
render(){
const { isLoading} = this.state;
return(
<div>{this.state.isLoading ? "Loading" : "We are ready"}</div>
)
}
}
export default App;