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 user3405663user34056631 Answer
Reset to default 7Since 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
评论列表(0条)