From 9e5feb2ca327de569450ccf50067263398ab5c60 Mon Sep 17 00:00:00 2001 From: Krzysztof Borowy Date: Wed, 21 Jun 2017 20:34:14 +0200 Subject: [PATCH] Moved propTypes checking, fixed undefined error (#2464) --- examples/counter/src/components/Counter.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/counter/src/components/Counter.js b/examples/counter/src/components/Counter.js index 344a7d9d71..052f02bf07 100644 --- a/examples/counter/src/components/Counter.js +++ b/examples/counter/src/components/Counter.js @@ -2,19 +2,19 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' class Counter extends Component { - static propTypes = { - value: PropTypes.number.isRequired, - onIncrement: PropTypes.func.isRequired, - onDecrement: PropTypes.func.isRequired + constructor(props) { + super(props); + this.incrementAsync = this.incrementAsync.bind(this); + this.incrementIfOdd = this.incrementIfOdd.bind(this); } - incrementIfOdd = () => { + incrementIfOdd() { if (this.props.value % 2 !== 0) { this.props.onIncrement() } } - incrementAsync = () => { + incrementAsync() { setTimeout(this.props.onIncrement, 1000) } @@ -44,4 +44,10 @@ class Counter extends Component { } } +Counter.propTypes = { + value: PropTypes.number.isRequired, + onIncrement: PropTypes.func.isRequired, + onDecrement: PropTypes.func.isRequired +} + export default Counter