-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter.jsx
36 lines (28 loc) · 925 Bytes
/
counter.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'react';
import ReactDOM from 'react-dom';
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {count: props.initialCount};
}
incrementCount() {
this.setState({ count: this.state.count + 1 });
}
decrementCount() {
this.setState({ count: this.state.count - 1 });
}
render() {
return (
<div>
<div className="my_counter">
<font size='+2'>Click counter: {this.state.count}</font>
</div>
<button type="Increment" id="but_up" onClick={ e => this.incrementCount(e)}>Increment</button>
<button type="Decrement" id="but_down" onClick={ e => this.decrementCount(e)}>Decrement</button>
</div>
)
}
}
Counter.propTypes = { initialCount: React.PropTypes.number };
Counter.defaultProps = { initialCount: 0 };
ReactDOM.render(<Counter initialCount={42}/>, document.getElementById('counter'));