Skip to content

Instantly share code, notes, and snippets.

@jubstuff
Created January 20, 2016 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jubstuff/072e86602ea141f83489 to your computer and use it in GitHub Desktop.
Save jubstuff/072e86602ea141f83489 to your computer and use it in GitHub Desktop.
A simple button in React that cycles between multiple states
var GiustinoButton = React.createClass({
getInitialState: function() {
return {
current_state: 1,
name: "A"
};
},
stateSwitcher: function() {
switch(this.state.current_state) {
case 1: return {current_state: 2, name: "B"}
case 2: return {current_state: 3, name: "C"}
case 3: return {current_state: 4, name: "D"}
case 4: return {current_state: 1, name: "A"}
}
},
handleClick: function() {
this.setState(this.stateSwitcher());
},
render: function() {
return <input type="submit" value={this.state.name} onClick={this.handleClick} />
}
});
ReactDOM.render(
<GiustinoButton />,
document.getElementById('container')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment