Skip to content

Instantly share code, notes, and snippets.

@elboman
Created August 6, 2016 00:34
Show Gist options
  • Save elboman/c82db34fdfc77fd29dbee85b25d18da3 to your computer and use it in GitHub Desktop.
Save elboman/c82db34fdfc77fd29dbee85b25d18da3 to your computer and use it in GitHub Desktop.
counter-example
import React, { Component } from 'react';
export default class Counter extends Component {
constructor (props) {
super(props);
this.state = {counter:0};
}
change = (val) => () => this.setState({counter:(this.state.counter + val)});
render () {
return (
<div style={divStyle}>
<button style={buttonStyle} onClick={this.change(-1)}>-1</button>
<span style={counterStyle}>{this.state.counter}</span>
<button style={buttonStyle} onClick={this.change(+1)}>+1</button>
</div>
);
}
}
const divStyle = {
fontFamily: '"Raleway", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif'
}
const buttonStyle = {
display: "inline-block",
height: 38,
padding: "0 30px",
color: "#555",
textAlign: "center",
fontSize: 13,
fontWeight: 600,
lineHeight: 0,
letterSpacing: ".1rem",
textTransform: "uppercase",
textDecoration: "none",
whiteSpace: "nowrap",
backgroundColor: "transparent",
borderRadius: 4,
border: "1px solid #bbb",
cursor: "pointer",
boxSizing: "border-box",
margin:5
}
const counterStyle = {
display: "inline-block",
fontWeight: 900,
width: 100,
fontSize: 22,
color: "#000"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment