Skip to content

Conversation

@zuberman
Copy link

@zuberman zuberman commented Oct 7, 2018

No description provided.



handleSearchSubmit(){
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 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;
Copy link
Contributor

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>
Copy link
Contributor

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>
)
Copy link
Contributor

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>
Copy link
Contributor

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 = {
Copy link
Contributor

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>
Copy link
Contributor

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

@dmitrigrabov
Copy link
Contributor

Good work. Some code duplication could be removed using loops

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