React.addons.cloneWithProps链接事件处理程序

时间:2014-12-17 11:58:58

标签: javascript reactjs

React.addons.cloneWithProps为什么以及如何对事件处理程序进行链接?

// All props were transferred from <Element /> to its child.
// Event handlers from <Element /> will chain with event handlers from its child.
var Case2 = React.createClass({
    render: function () {
        var child = React.Children.only(this.props.children);
        return React.addons.cloneWithProps(child, this.props);
    }
});

// All props were transferred from <Element /> to its child.
// Event handlers from <Element /> will override event handlers from its child.
var Case3 = React.createClass({
    render: function () {
        var child = React.Children.only(this.props.children);
        return React.addons.cloneWithProps(child, _.omit(this.props, 'children'));        
    }
});

这是official documentation of the React.addons.cloneWithProps。它没有说明这种行为。

这是fiddle

0 个答案:

没有答案