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 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>);
本文标签: javascriptReactjs map returns unexpected token Stack Overflow
版权声明:本文标题:javascript - Reactjs map returns unexpected token } - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745215610a2648146.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论