admin管理员组

文章数量:1415145

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>);

本文标签: javascriptReactjs map returns unexpected token Stack Overflow