Created
February 24, 2017 13:41
-
-
Save zgababa/4fbb8deafa425e46cdff382d59781953 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import React from 'react'; | |
import getPokemon from '../client/getPokemon'; | |
class Pokedex extends React.Component { | |
constructor() { | |
super(); | |
this.state = {id : 0}; | |
this.arrowRight = this.arrowRight.bind(this); | |
this.arrowLeft = this.arrowLeft.bind(this); | |
} | |
makeRequest(id) { | |
return getPokemon(id) | |
.then((data) => { | |
console.log(data); | |
this.setState({ | |
id | |
}); | |
} | |
); | |
} | |
arrowRight() { | |
this.makeRequest(this.state.id + 1); | |
} | |
arrowLeft() { | |
if (this.state.id) { | |
this.makeRequest(this.state.id - 1); | |
} | |
} | |
render() { | |
return ( | |
<div> | |
Hello World ! | |
<button onClick={this.arrowLeft}>Left</button> | |
<button onClick={this.arrowRight}>Right</button> | |
</div> | |
); | |
} | |
}; | |
export default Pokedex; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment