javascript - Reactjs map returns unexpected token } - Stack Overflow

I've been looking for this error, but haven't found it anywhere. I'm new to React and fo

I've been looking for this error, but haven't found it anywhere. I'm new to React and following some tutorials. Everything has worked up to the point where I'm trying to map an array to a ponent.

so I'm using dummy data to test this function in a smaller form

var data = [
    {name: 'You', text: 'Test'},
    {name: 'Me', text: 'Testing'}
];

Now I am trying to print out a ment system, and for now I'm only trying to print out the names of the users. I'm giving my application ponent the data, which gives it to the messagelist. There I'm trying to print them into boxes.

var MessageList = React.createClass({
    render: function() {
        var messages = this.props.data.map(function(msg) { 
            return <MessageBox name={msg.name} />
        });    //**** ERROR HERE ****
        return {messages};
    }
});

I indicated the line where the error occurs.

Uncaught SyntaxError: Unexpected token }

I don't think I need to add any additional info as all other features were working fine, this is the only thing that returns an error. Hope you guys can help me.

I've been looking for this error, but haven't found it anywhere. I'm new to React and following some tutorials. Everything has worked up to the point where I'm trying to map an array to a ponent.

so I'm using dummy data to test this function in a smaller form

var data = [
    {name: 'You', text: 'Test'},
    {name: 'Me', text: 'Testing'}
];

Now I am trying to print out a ment system, and for now I'm only trying to print out the names of the users. I'm giving my application ponent the data, which gives it to the messagelist. There I'm trying to print them into boxes.

var MessageList = React.createClass({
    render: function() {
        var messages = this.props.data.map(function(msg) { 
            return <MessageBox name={msg.name} />
        });    //**** ERROR HERE ****
        return {messages};
    }
});

I indicated the line where the error occurs.

Uncaught SyntaxError: Unexpected token }

I don't think I need to add any additional info as all other features were working fine, this is the only thing that returns an error. Hope you guys can help me.

Share Improve this question asked Nov 24, 2014 at 15:12 user3405663user3405663
Add a ment  | 

1 Answer 1

Reset to default 7

Since messages is an array and your ponent should return one single element, you should wrap it with another ponent:

return (<div>{messages}</div>);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745215610a4617000.html

相关推荐

  • javascript - Reactjs map returns unexpected token } - Stack Overflow

    I've been looking for this error, but haven't found it anywhere. I'm new to React and fo

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信