我将两个值传递给子组件:
- 要显示的对象列表
- 删除功能.
我使用.map()函数来显示我的对象列表(类似于Reaction教程页面中给出的示例),但是该组件中的按钮在渲染时触发onClick
函数(它不应该在渲染时触发).我的代码如下所示:
module.exports = React.createClass({
render: function(){
var taskNodes = this.props.todoTasks.map(function(todo){
return (
<div>
{todo.task}
<button type="submit" onClick={this.props.removeTaskFunction(todo)}>Submit</button>
</div>
);
}, this);
return (
<div className="todo-task-list">
{taskNodes}
</div>
);
}
});
我的问题是:为什么onClick
函数会在渲染时启动,以及如何使其不启动?