Skip to content

Commit 9e5feb2

Browse files
krizzutimdorr
authored andcommitted
Moved propTypes checking, fixed undefined error (#2464)
1 parent 689c800 commit 9e5feb2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

examples/counter/src/components/Counter.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import React, { Component } from 'react'
22
import PropTypes from 'prop-types'
33

44
class Counter extends Component {
5-
static propTypes = {
6-
value: PropTypes.number.isRequired,
7-
onIncrement: PropTypes.func.isRequired,
8-
onDecrement: PropTypes.func.isRequired
5+
constructor(props) {
6+
super(props);
7+
this.incrementAsync = this.incrementAsync.bind(this);
8+
this.incrementIfOdd = this.incrementIfOdd.bind(this);
99
}
1010

11-
incrementIfOdd = () => {
11+
incrementIfOdd() {
1212
if (this.props.value % 2 !== 0) {
1313
this.props.onIncrement()
1414
}
1515
}
1616

17-
incrementAsync = () => {
17+
incrementAsync() {
1818
setTimeout(this.props.onIncrement, 1000)
1919
}
2020

@@ -44,4 +44,10 @@ class Counter extends Component {
4444
}
4545
}
4646

47+
Counter.propTypes = {
48+
value: PropTypes.number.isRequired,
49+
onIncrement: PropTypes.func.isRequired,
50+
onDecrement: PropTypes.func.isRequired
51+
}
52+
4753
export default Counter

0 commit comments

Comments
 (0)