如何使其用作增量按钮:
import React, { Component } from 'react';
export default class Logon extends Component{
constructor(props){
super(props);
this.state = {
counter: 0
}
}
render(){
return(
<button onClick={() => {this.state.counter = this.state.counter + 1}}>
{this.state.counter}
</button>
);
}
答案 0 :(得分:2)
You need to call the `setState` to set the value of state in React.
<button onClick={() => {this.setState({counter: counter+1})}>
{this.state.counter}
</button>
在React js中引用State