-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
70 lines (58 loc) · 1.57 KB
/
App.js
File metadata and controls
70 lines (58 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, { Component } from 'react';
import './App.css';
import PropTypes from 'prop-types';
import Movie from './Movie';
class App extends Component {
//Render : componentWillMount() -> render() -> componentDidMount()
//Update : componentWillReceiveProps -> shouldComponentUpdate() -> componentWillUpdate() -> render() 0
componentWillMount(){
console.log("will mount")
}
componentDidMount(){
this._getMovies();
}
componentWillReceiveProps() {
console.log("receive props")
}
static propTypes = {
title: PropTypes.string,
poster: PropTypes.string,
genres: PropTypes.array,
synopsis: PropTypes.string,
}
state = {
}
_callAPI = () => {
return fetch('https://yts.am/api/v2/list_movies.json?sort_by=like_count')
.then(response => response.json())
.then(json => json.data.movies)
.catch(err => console.log(err))
}
_getMovies = async () => {
const movies = await this._callAPI()
this.setState({
movies
})
}
_renderMovies = () => {
const movies = this.state.movies.map((movie) => {
return <Movie
title={movie.title_english}
poster={movie.medium_cover_image}
genres={movie.genres}
synopsis={movie.synopsis}
key={movie.id} />
})
return movies
}
render() {
const { movies } = this.state;
console.log("render")
return (
<div className={movies ? "App" : "App--loading"}>
{this.state.movies ? this._renderMovies() : 'Loading'}
</div>
)
}
}
export default App;