Movie info website (React, axios and Semantic UI)











up vote
3
down vote

favorite
1












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?










share|improve this question




























    up vote
    3
    down vote

    favorite
    1












    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?










    share|improve this question


























      up vote
      3
      down vote

      favorite
      1









      up vote
      3
      down vote

      favorite
      1






      1





      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      200_success

      127k15148412




      127k15148412










      asked May 10 '17 at 17:20









      Isa Kurehpaz

      161




      161






















          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 in componentDidMount because componentWillMount 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
            );
            }







          share|improve this answer





















            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "196"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            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

























            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 in componentDidMount because componentWillMount 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
              );
              }







            share|improve this answer

























              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 in componentDidMount because componentWillMount 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
                );
                }







              share|improve this answer























                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 in componentDidMount because componentWillMount 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
                  );
                  }







                share|improve this answer












                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 in componentDidMount because componentWillMount 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
                  );
                  }








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 days ago









                ByteSettlement

                132210




                132210






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Ellipse (mathématiques)

                    Quarter-circle Tiles

                    Mont Emei