在利用npm的create-react-app快速创建一个app时,当访问页面时总是报一个错误,但是这个错误我真是想不明白呀。
下面是源码:
import React, {Component} from 'react';
class Counter extends Component (
constructor(props){
super(props);
this.onClickIncrementButton = this.onClickIncrementButton.bin(this);
this.onClickDecrementButton = this.onClickDecrementButton.bin(this);
this.status = {
count : props.initValue
}
}
onClickIncrementButton() {
this.setState({count : this.state.count + 1});
}
onClickDecrementButton() {
this.setState({count : this.state.count - 1});
}
render(){
const {caption} = this.props;
return (
<div>
<button onClick={this.onClickIncrementButton}>+</button>
<button onClick={this.onClickDecrementButton}>+</button>
<span>{caption} count : {this.state.count}</span>
</div>
);
}
)
Counter.propType = {
caption : PropType.string.isRequired,
initValue : PropType.number
};
Counter.defaultProps = {
initValue : 0
};
export default Counter;