-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pokemon game #4
base: master
Are you sure you want to change the base?
Pokemon game #4
Conversation
|
||
|
||
handleSearchSubmit(){ | ||
this.setState({ |
There was a problem hiding this comment.
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 pre-calculate the searchList
. That way you can set it in state and use it the fetch after without needing the use the callback in setState. Keeps code simpler
} | ||
|
||
generateComputerCard(){ | ||
let randomPokemonNumber = Math.floor(Math.random() * (800 - 1 + 1)) + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
800 - 1 + 1 ?
<div className="card"> | ||
{this.props.playerCard.name}<br></br> | ||
<img className="sprite" src={this.props.playerCard.sprites.front_shiny} /><br></br> | ||
Speed: {this.props.playerCard.stats[0].base_stat}<button stat={this.props.playerCard.stats[0].base_stat} name="speed" onClick={ event => this.props.handleClick(this.props.playerCard.stats[0].base_stat, this.props.computerCard.stats[0].base_stat) }>Select</button><br></br> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this might better generated using a loop rather than code duplication. The only difference between the rows is the label and index. You could create an array of labels, map over them and generate each button using the label from array and its index
{this.props.team[${this.state.currentCardIndex}].name} | ||
{pokemon.stats[${this.state.currentCardIndex}].stat.name}{pokemon.stats[${this.state.currentCardIndex}].base_stat}<button onClick={event => this.handleClick(pokemon)}>Select</button> | ||
</div> | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation could be better here
<tbody> | ||
<tr> | ||
<th>{this.props.pokemon.name}</th> | ||
<th>{this.props.pokemon.stats[0].stat.name}</th> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some loops could reduce code duplication here
constructor(){ | ||
super(); | ||
|
||
this.state = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be removed
<tbody> | ||
<tr> | ||
<th>{pokemon.name}</th> | ||
<th>{pokemon.stats[0].stat.name}</th> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using a loop here to generate each line would reduce code duplication
Good work. Some code duplication could be removed using loops |
No description provided.