Skip to content

Conversation

@jay9044
Copy link

@jay9044 jay9044 commented Oct 3, 2018

No description provided.


this.setState({
page: this.state.page + 1
}, () => this.fetchMovies(this.state.userSearch,this.setState.page))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to access page from state you need to use this.state.page rather than this.setState.page. setState is a method used to change state rather than get values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it would be better to avoid using the setState callback here, by calculating next page number, storing it in a variable and then you can pass both to setState and fetchMovies

handlePrevClick(){
this.setState({
page: this.state.page - 1
},() => this.fetchMovies(this.state.userSearch, this.setState.page))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

@@ -0,0 +1,13 @@
import React from 'react';

class Button extends React.Component {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this component is not used anywhere

fetch(`http://www.omdbapi.com/?apikey=8d5ab09&i=${this.props.movie.imdbID}`)
.then(response => response.json())
.then(body =>
this.setState({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to store the returned movie object in state and generate the strings to display to user in render method

class Search extends React.Component {
constructor(){
super()
this.state = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the search query is stored both in Search and App. It would better to avoid state duplication and pass the search query down from App to Search

@dmitrigrabov
Copy link
Contributor

Good work. A few bits could be tidied up. Take a look at the comments for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants