1
我在做什麼錯,我不斷收到TypeError:無法讀取屬性'計數'爲null。我沒有正確設置初始狀態嗎?反應初始狀態。計數
import React from 'react';
class User extends React.Component {
\t super(props){
\t \t this.state = {
\t \t \t count: 0
\t \t }
\t }
\t increment(){
\t \t this.setState({ count: this.state.count + 1 })
\t }
\t render(){
\t \t return(<div>
\t \t \t <button
\t \t \t \t onClick={this.increment}>
\t \t \t \t \t \t {this.state.count}
\t \t \t </button>
\t \t </div>)
\t }
}
export default User;
感謝你的人 –