我正试着在ReactJs中做一些类似手风琴的事情。现在我有3个组件:<TableList>、<TableListGroupRow>、<TableListRow>
在List render方法中,我将GroupRows和行推入一个数组,然后再呈现该数组。
//one group row for example
var group;
tableRows.push(
group =
<TableListGroupRow
onClick={
我开始注意到一种不寻常的模式。任何onClick事件都需要语法为onClick={() => «name of function»}。我还花了很多时间研究为什么onClick似乎是唯一需要偏执的事件处理程序,但我所能找到的只是一些文章,它们解释了该做什么,但没有解释为什么它会那样工作。OnChange和其他事件不需要相同的语法,但它们都是事件的类型。欢迎所有建议和解释。
在使用React时,我理解它,因此在组件的render方法中调用setState是错误的做法;相反,请保持此方法的纯正性。但是,如果我需要基于链接到组件的事件来更新状态,我如何做到这一点?
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state = {isToggleOn: true};
// This binding is necessary to make `this` work in the callback
this.handleCl