Movie info website (React, axios and Semantic UI)
up vote
3
down vote
favorite
import React, { Component } from 'react';
import { Grid, Header, Divider, Image, Embed, Button, Icon } from 'semantic-ui-react'
import axios from 'axios';
class Movie extends Component {
constructor(props) {
super(props);
this.state = {
title: '',
year: '',
poster: '',
plot: '',
rating: '',
genres: '',
runtime: ''
};
}
componentWillMount() {
axios.get('http://www.omdbapi.com/?i=tt0096895')
.then((response) => {
console.log(response.data);
this.setState(
{
title: response.data.Title,
year: response.data.Year,
poster: response.data.Poster,
plot: response.data.Plot,
rating: response.data.imdbRating,
genres: response.data.Genre,
runtime: response.data.Runtime
})
})
.catch((err) => {
console.log(err);
});
}
render() {
return (
<div>
<Grid container>
<Grid.Column width={5}>
<Image
src={this.state.poster}
fluid
/>
<Button attached='top'>
<Icon name='plus'/>
Add to watchlist
</Button>
<Divider section/>
<h4>RATING</h4>
<img className='imdb-icon' src="https://lh3.googleusercontent.com/lOC6oCAWrB7TNqvPdgJkQzUyC2pLc63n0iLCBtIE9CF-FFUjbbiAyW9AUPiCfkz3nOUxNE0SVZtxGsKRwDPsHqpOuHYadm2lEhx6wfobYyoPp8CfV3tO65ZTjJ8-91vT9Q7lwrOvDQF_sIOUGJ32TeIYdgWXHLiM3RNYS5LUq1fL71l5nL_37He7XokgUO6lbuwPOm7nNEAyBuyQgYzPgB-hxkzSGeUg6o4Tp7dAz8O3X6Cuhhxew-N23-zgqr4ag3dZ9L4De21WLO-WppAmgh752F4uY4Zt-IrbtxldHnOkve8OX3ktlRCHkrtcdHVL9jCWruyBpn3KZhL2fuMZ9oeWSVU3v4Gpkxb5xlh3MTveT8N45ih3WAYoP6Hm-Jz8qAhMQpfnmSRGzuQaX22FITypo_XeKcvkoSLUQMC1V68nuWcOT2MphDFyMgTjunmLBca74UpL5s3k2_FhJfS0RX0k0Y6IC6bUOL5gWcEu0d4rJv8iJHnXKft4zohH4PryAuE-G2q7rs4Vnb_65grz89QQGmF6OLGUhZowBfnGD8_MRE6Ev9Q92x8hMSFWZJZsz2wNk0eUxnCVSJFNVO1jphG2bSHy6ojYNVe9b-JVVQ3NlJr9KjB6=w64-h32-no"/>
<span>{this.state.rating}</span>
<h4>GENRES</h4>
<p>{this.state.genres}</p>
<h4>RUNTIME</h4>
<p>{this.state.runtime}</p>
<Divider section/>
</Grid.Column>
<Grid.Column width={11}>
<Header as='h2' inverted>
{this.state.title}
<Header.Subheader>
({this.state.year})
</Header.Subheader>
</Header>
<Embed id='O6Xo21L0ybE' source='youtube'/>
<h4>PLOT</h4>
<p>{this.state.plot}</p>
</Grid.Column>
</Grid>
</div>
);
}
}
export default Movie;
I am very new to React. This is for a school project and I would love to if someone reviewed my code. What improvements can I do?
beginner homework react.js jsx
add a comment |
up vote
3
down vote
favorite
import React, { Component } from 'react';
import { Grid, Header, Divider, Image, Embed, Button, Icon } from 'semantic-ui-react'
import axios from 'axios';
class Movie extends Component {
constructor(props) {
super(props);
this.state = {
title: '',
year: '',
poster: '',
plot: '',
rating: '',
genres: '',
runtime: ''
};
}
componentWillMount() {
axios.get('http://www.omdbapi.com/?i=tt0096895')
.then((response) => {
console.log(response.data);
this.setState(
{
title: response.data.Title,
year: response.data.Year,
poster: response.data.Poster,
plot: response.data.Plot,
rating: response.data.imdbRating,
genres: response.data.Genre,
runtime: response.data.Runtime
})
})
.catch((err) => {
console.log(err);
});
}
render() {
return (
<div>
<Grid container>
<Grid.Column width={5}>
<Image
src={this.state.poster}
fluid
/>
<Button attached='top'>
<Icon name='plus'/>
Add to watchlist
</Button>
<Divider section/>
<h4>RATING</h4>
<img className='imdb-icon' src="https://lh3.googleusercontent.com/lOC6oCAWrB7TNqvPdgJkQzUyC2pLc63n0iLCBtIE9CF-FFUjbbiAyW9AUPiCfkz3nOUxNE0SVZtxGsKRwDPsHqpOuHYadm2lEhx6wfobYyoPp8CfV3tO65ZTjJ8-91vT9Q7lwrOvDQF_sIOUGJ32TeIYdgWXHLiM3RNYS5LUq1fL71l5nL_37He7XokgUO6lbuwPOm7nNEAyBuyQgYzPgB-hxkzSGeUg6o4Tp7dAz8O3X6Cuhhxew-N23-zgqr4ag3dZ9L4De21WLO-WppAmgh752F4uY4Zt-IrbtxldHnOkve8OX3ktlRCHkrtcdHVL9jCWruyBpn3KZhL2fuMZ9oeWSVU3v4Gpkxb5xlh3MTveT8N45ih3WAYoP6Hm-Jz8qAhMQpfnmSRGzuQaX22FITypo_XeKcvkoSLUQMC1V68nuWcOT2MphDFyMgTjunmLBca74UpL5s3k2_FhJfS0RX0k0Y6IC6bUOL5gWcEu0d4rJv8iJHnXKft4zohH4PryAuE-G2q7rs4Vnb_65grz89QQGmF6OLGUhZowBfnGD8_MRE6Ev9Q92x8hMSFWZJZsz2wNk0eUxnCVSJFNVO1jphG2bSHy6ojYNVe9b-JVVQ3NlJr9KjB6=w64-h32-no"/>
<span>{this.state.rating}</span>
<h4>GENRES</h4>
<p>{this.state.genres}</p>
<h4>RUNTIME</h4>
<p>{this.state.runtime}</p>
<Divider section/>
</Grid.Column>
<Grid.Column width={11}>
<Header as='h2' inverted>
{this.state.title}
<Header.Subheader>
({this.state.year})
</Header.Subheader>
</Header>
<Embed id='O6Xo21L0ybE' source='youtube'/>
<h4>PLOT</h4>
<p>{this.state.plot}</p>
</Grid.Column>
</Grid>
</div>
);
}
}
export default Movie;
I am very new to React. This is for a school project and I would love to if someone reviewed my code. What improvements can I do?
beginner homework react.js jsx
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
import React, { Component } from 'react';
import { Grid, Header, Divider, Image, Embed, Button, Icon } from 'semantic-ui-react'
import axios from 'axios';
class Movie extends Component {
constructor(props) {
super(props);
this.state = {
title: '',
year: '',
poster: '',
plot: '',
rating: '',
genres: '',
runtime: ''
};
}
componentWillMount() {
axios.get('http://www.omdbapi.com/?i=tt0096895')
.then((response) => {
console.log(response.data);
this.setState(
{
title: response.data.Title,
year: response.data.Year,
poster: response.data.Poster,
plot: response.data.Plot,
rating: response.data.imdbRating,
genres: response.data.Genre,
runtime: response.data.Runtime
})
})
.catch((err) => {
console.log(err);
});
}
render() {
return (
<div>
<Grid container>
<Grid.Column width={5}>
<Image
src={this.state.poster}
fluid
/>
<Button attached='top'>
<Icon name='plus'/>
Add to watchlist
</Button>
<Divider section/>
<h4>RATING</h4>
<img className='imdb-icon' src="https://lh3.googleusercontent.com/lOC6oCAWrB7TNqvPdgJkQzUyC2pLc63n0iLCBtIE9CF-FFUjbbiAyW9AUPiCfkz3nOUxNE0SVZtxGsKRwDPsHqpOuHYadm2lEhx6wfobYyoPp8CfV3tO65ZTjJ8-91vT9Q7lwrOvDQF_sIOUGJ32TeIYdgWXHLiM3RNYS5LUq1fL71l5nL_37He7XokgUO6lbuwPOm7nNEAyBuyQgYzPgB-hxkzSGeUg6o4Tp7dAz8O3X6Cuhhxew-N23-zgqr4ag3dZ9L4De21WLO-WppAmgh752F4uY4Zt-IrbtxldHnOkve8OX3ktlRCHkrtcdHVL9jCWruyBpn3KZhL2fuMZ9oeWSVU3v4Gpkxb5xlh3MTveT8N45ih3WAYoP6Hm-Jz8qAhMQpfnmSRGzuQaX22FITypo_XeKcvkoSLUQMC1V68nuWcOT2MphDFyMgTjunmLBca74UpL5s3k2_FhJfS0RX0k0Y6IC6bUOL5gWcEu0d4rJv8iJHnXKft4zohH4PryAuE-G2q7rs4Vnb_65grz89QQGmF6OLGUhZowBfnGD8_MRE6Ev9Q92x8hMSFWZJZsz2wNk0eUxnCVSJFNVO1jphG2bSHy6ojYNVe9b-JVVQ3NlJr9KjB6=w64-h32-no"/>
<span>{this.state.rating}</span>
<h4>GENRES</h4>
<p>{this.state.genres}</p>
<h4>RUNTIME</h4>
<p>{this.state.runtime}</p>
<Divider section/>
</Grid.Column>
<Grid.Column width={11}>
<Header as='h2' inverted>
{this.state.title}
<Header.Subheader>
({this.state.year})
</Header.Subheader>
</Header>
<Embed id='O6Xo21L0ybE' source='youtube'/>
<h4>PLOT</h4>
<p>{this.state.plot}</p>
</Grid.Column>
</Grid>
</div>
);
}
}
export default Movie;
I am very new to React. This is for a school project and I would love to if someone reviewed my code. What improvements can I do?
beginner homework react.js jsx
import React, { Component } from 'react';
import { Grid, Header, Divider, Image, Embed, Button, Icon } from 'semantic-ui-react'
import axios from 'axios';
class Movie extends Component {
constructor(props) {
super(props);
this.state = {
title: '',
year: '',
poster: '',
plot: '',
rating: '',
genres: '',
runtime: ''
};
}
componentWillMount() {
axios.get('http://www.omdbapi.com/?i=tt0096895')
.then((response) => {
console.log(response.data);
this.setState(
{
title: response.data.Title,
year: response.data.Year,
poster: response.data.Poster,
plot: response.data.Plot,
rating: response.data.imdbRating,
genres: response.data.Genre,
runtime: response.data.Runtime
})
})
.catch((err) => {
console.log(err);
});
}
render() {
return (
<div>
<Grid container>
<Grid.Column width={5}>
<Image
src={this.state.poster}
fluid
/>
<Button attached='top'>
<Icon name='plus'/>
Add to watchlist
</Button>
<Divider section/>
<h4>RATING</h4>
<img className='imdb-icon' src="https://lh3.googleusercontent.com/lOC6oCAWrB7TNqvPdgJkQzUyC2pLc63n0iLCBtIE9CF-FFUjbbiAyW9AUPiCfkz3nOUxNE0SVZtxGsKRwDPsHqpOuHYadm2lEhx6wfobYyoPp8CfV3tO65ZTjJ8-91vT9Q7lwrOvDQF_sIOUGJ32TeIYdgWXHLiM3RNYS5LUq1fL71l5nL_37He7XokgUO6lbuwPOm7nNEAyBuyQgYzPgB-hxkzSGeUg6o4Tp7dAz8O3X6Cuhhxew-N23-zgqr4ag3dZ9L4De21WLO-WppAmgh752F4uY4Zt-IrbtxldHnOkve8OX3ktlRCHkrtcdHVL9jCWruyBpn3KZhL2fuMZ9oeWSVU3v4Gpkxb5xlh3MTveT8N45ih3WAYoP6Hm-Jz8qAhMQpfnmSRGzuQaX22FITypo_XeKcvkoSLUQMC1V68nuWcOT2MphDFyMgTjunmLBca74UpL5s3k2_FhJfS0RX0k0Y6IC6bUOL5gWcEu0d4rJv8iJHnXKft4zohH4PryAuE-G2q7rs4Vnb_65grz89QQGmF6OLGUhZowBfnGD8_MRE6Ev9Q92x8hMSFWZJZsz2wNk0eUxnCVSJFNVO1jphG2bSHy6ojYNVe9b-JVVQ3NlJr9KjB6=w64-h32-no"/>
<span>{this.state.rating}</span>
<h4>GENRES</h4>
<p>{this.state.genres}</p>
<h4>RUNTIME</h4>
<p>{this.state.runtime}</p>
<Divider section/>
</Grid.Column>
<Grid.Column width={11}>
<Header as='h2' inverted>
{this.state.title}
<Header.Subheader>
({this.state.year})
</Header.Subheader>
</Header>
<Embed id='O6Xo21L0ybE' source='youtube'/>
<h4>PLOT</h4>
<p>{this.state.plot}</p>
</Grid.Column>
</Grid>
</div>
);
}
}
export default Movie;
I am very new to React. This is for a school project and I would love to if someone reviewed my code. What improvements can I do?
beginner homework react.js jsx
beginner homework react.js jsx
edited 2 days ago
200_success
127k15148412
127k15148412
asked May 10 '17 at 17:20
Isa Kurehpaz
161
161
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Some things I would change:
Make initial state look like this:
this.state = {
movie: null
};
Instead of making the api request in
componentWillMount
, do it incomponentDidMount
becausecomponentWillMount
is considered legacy.
In
componentDidMount
be more declarative, which means to be more descriptive of what you are doing, so call a method that gets the movie like this:
componentDidMount() {
this.getMovie();
}
getMovie()
would look like this:
getMovie() {
axios
.get("http://www.omdbapi.com/?i=tt0096895")
.then(response => {
const movie = {
title: response.data.Title,
year: response.data.Year,
poster: response.data.Poster,
plot: response.data.Plot,
rating: response.data.imdbRating,
genres: response.data.Genre,
runtime: response.data.Runtime
};
this.setMovie(movie);
})
.catch(err => {
console.log(err);
});
}
setMovie(movie)
:
setMovie(movie) {
this.setState({ movie });
}
Lastly, in your render, I would check if there was a movie on state before rendering anything, if there is no movie, display some text saying no movie.
render() {
if (!this.state.movie) {
return <p>No movie found.</p>;
}
return (
...what you currently have
);
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Some things I would change:
Make initial state look like this:
this.state = {
movie: null
};
Instead of making the api request in
componentWillMount
, do it incomponentDidMount
becausecomponentWillMount
is considered legacy.
In
componentDidMount
be more declarative, which means to be more descriptive of what you are doing, so call a method that gets the movie like this:
componentDidMount() {
this.getMovie();
}
getMovie()
would look like this:
getMovie() {
axios
.get("http://www.omdbapi.com/?i=tt0096895")
.then(response => {
const movie = {
title: response.data.Title,
year: response.data.Year,
poster: response.data.Poster,
plot: response.data.Plot,
rating: response.data.imdbRating,
genres: response.data.Genre,
runtime: response.data.Runtime
};
this.setMovie(movie);
})
.catch(err => {
console.log(err);
});
}
setMovie(movie)
:
setMovie(movie) {
this.setState({ movie });
}
Lastly, in your render, I would check if there was a movie on state before rendering anything, if there is no movie, display some text saying no movie.
render() {
if (!this.state.movie) {
return <p>No movie found.</p>;
}
return (
...what you currently have
);
}
add a comment |
up vote
1
down vote
Some things I would change:
Make initial state look like this:
this.state = {
movie: null
};
Instead of making the api request in
componentWillMount
, do it incomponentDidMount
becausecomponentWillMount
is considered legacy.
In
componentDidMount
be more declarative, which means to be more descriptive of what you are doing, so call a method that gets the movie like this:
componentDidMount() {
this.getMovie();
}
getMovie()
would look like this:
getMovie() {
axios
.get("http://www.omdbapi.com/?i=tt0096895")
.then(response => {
const movie = {
title: response.data.Title,
year: response.data.Year,
poster: response.data.Poster,
plot: response.data.Plot,
rating: response.data.imdbRating,
genres: response.data.Genre,
runtime: response.data.Runtime
};
this.setMovie(movie);
})
.catch(err => {
console.log(err);
});
}
setMovie(movie)
:
setMovie(movie) {
this.setState({ movie });
}
Lastly, in your render, I would check if there was a movie on state before rendering anything, if there is no movie, display some text saying no movie.
render() {
if (!this.state.movie) {
return <p>No movie found.</p>;
}
return (
...what you currently have
);
}
add a comment |
up vote
1
down vote
up vote
1
down vote
Some things I would change:
Make initial state look like this:
this.state = {
movie: null
};
Instead of making the api request in
componentWillMount
, do it incomponentDidMount
becausecomponentWillMount
is considered legacy.
In
componentDidMount
be more declarative, which means to be more descriptive of what you are doing, so call a method that gets the movie like this:
componentDidMount() {
this.getMovie();
}
getMovie()
would look like this:
getMovie() {
axios
.get("http://www.omdbapi.com/?i=tt0096895")
.then(response => {
const movie = {
title: response.data.Title,
year: response.data.Year,
poster: response.data.Poster,
plot: response.data.Plot,
rating: response.data.imdbRating,
genres: response.data.Genre,
runtime: response.data.Runtime
};
this.setMovie(movie);
})
.catch(err => {
console.log(err);
});
}
setMovie(movie)
:
setMovie(movie) {
this.setState({ movie });
}
Lastly, in your render, I would check if there was a movie on state before rendering anything, if there is no movie, display some text saying no movie.
render() {
if (!this.state.movie) {
return <p>No movie found.</p>;
}
return (
...what you currently have
);
}
Some things I would change:
Make initial state look like this:
this.state = {
movie: null
};
Instead of making the api request in
componentWillMount
, do it incomponentDidMount
becausecomponentWillMount
is considered legacy.
In
componentDidMount
be more declarative, which means to be more descriptive of what you are doing, so call a method that gets the movie like this:
componentDidMount() {
this.getMovie();
}
getMovie()
would look like this:
getMovie() {
axios
.get("http://www.omdbapi.com/?i=tt0096895")
.then(response => {
const movie = {
title: response.data.Title,
year: response.data.Year,
poster: response.data.Poster,
plot: response.data.Plot,
rating: response.data.imdbRating,
genres: response.data.Genre,
runtime: response.data.Runtime
};
this.setMovie(movie);
})
.catch(err => {
console.log(err);
});
}
setMovie(movie)
:
setMovie(movie) {
this.setState({ movie });
}
Lastly, in your render, I would check if there was a movie on state before rendering anything, if there is no movie, display some text saying no movie.
render() {
if (!this.state.movie) {
return <p>No movie found.</p>;
}
return (
...what you currently have
);
}
answered 2 days ago
ByteSettlement
132210
132210
add a comment |
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f163006%2fmovie-info-website-react-axios-and-semantic-ui%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown