Last active
January 16, 2018 20:59
-
-
Save shubich/1c26df8e422ec3eefcae145d3dc436b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from 'react'; | |
import { render } from 'react-dom'; | |
import './style.css'; | |
const cats = [ | |
"http://www.pawculture.com/uploads/small-cat-breeds-card.jpg", | |
"http://www.pawculture.com/uploads/cats-small-places-card.jpg", | |
"http://facts.net/wp-content/uploads/2015/07/Cat-Facts.jpg" | |
] | |
class App extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
cur: 0 | |
}; | |
} | |
handleToTheLeft = () => { | |
this.setState(function (state, props) { | |
return { | |
cur: this.state.cur ? this.state.cur - 1 : cats.length - 1, | |
} | |
}); | |
} | |
handleToTheRight = () => { | |
this.setState(function (state, props) { | |
return { | |
cur: (this.state.cur !== cats.length - 1) | |
? this.state.cur + 1 | |
: 0, | |
} | |
}); | |
} | |
render() { | |
return ( | |
<div> | |
<button onClick={this.handleToTheLeft}><</button> | |
<img src={cats[this.state.cur]} alt="cat" /> | |
<button onClick={this.handleToTheRight}>></button> | |
</div> | |
); | |
} | |
} | |
render(<App />, document.getElementById('root')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment