代码如下:import React, { Component } from 'react';class Counter extends Component {
state = { value: 0 };
increment = () => { this.setState(prevState => ({ value: prevState.value + 1
}));
};
decrement = () => { this.setState(prevState => ({ value: prevState.value - 1
}));
};
render() { return ( <div>
{this.state.value} <button onClick={this.increment}>+</button>
<button onClick={this.decrement}>-</button>
</div>
)
}
}主要是如下代码:不明白什么意思啊,文档上说this.setState()有回调函数,但是也米见过这种用法啊,这是什么鬼啊 increment = () => { this.setState(prevState => ({ value: prevState.value + 1
}));
};小弟刚刚自学react万望大家给解释一下,谢谢啦
添加回答
举报
0/150
提交
取消