Objects are not valid as a React child是什么鬼?

#1

Uncaught Error: Invariant Violation: Objects are not valid as a React child (found: object with keys {child}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of Matchs.

请问报这个错误是什么原因啊?代码如下:

var Matchs = React.createClass({
    render: function() {
        return (
            <div className="matchs">
                {React.Children.map(this.props.children, function (child) {
                    return {child};
                })}
            </div>
        );
    }
});

var MainWindow = React.createClass({
    render: function() {
        return (
            <div className="MainWindow">
                <Matchs>
                    {this.props.data.match.map(function (match_, index_) {
                        return <Match data={match_} />;
                    })}
                </Matchs>
            </div>
        );
    }
});
#2

找到问题了,把
return {child};

改为
return child;

2 Likes
#3

也遇到这个报错,发现原因是map里面某一项取值是对象 = =