Skip to content

Instantly share code, notes, and snippets.

@zgababa
Last active February 23, 2017 16:03
Show Gist options
  • Save zgababa/106eebbbf6db137c40550273d1b70dca to your computer and use it in GitHub Desktop.
Save zgababa/106eebbbf6db137c40550273d1b70dca to your computer and use it in GitHub Desktop.
'use strict';
import React from 'react';
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) {
this.setState({
id
}, () => {
console.log(this.state);
});
}
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