admin管理员组文章数量:1393889
For some reason that I can't figure it out I am getting a syntax error in the following React ponent. The error is in the first curly bracket
on the renderItem()
. What's wrong?
Thank you in advance.
import _ from 'lodash';
import React from 'react';
import { ToDoListHeader } from './todo-list-header';
import { ToDoListItem } from './todo-list-item';
export const ToDoList = (props) => {
renderItems() {
return _.map(this.props.todos, (todo, index) => <ToDoListItem key={index} {...todo} />)
}
return (
<div>
<table>
<ToDoListHeader />
<tbody>
{/* {this.renderItems()} */}
</tbody>
</table>
</div>
);
}
For some reason that I can't figure it out I am getting a syntax error in the following React ponent. The error is in the first curly bracket
on the renderItem()
. What's wrong?
Thank you in advance.
import _ from 'lodash';
import React from 'react';
import { ToDoListHeader } from './todo-list-header';
import { ToDoListItem } from './todo-list-item';
export const ToDoList = (props) => {
renderItems() {
return _.map(this.props.todos, (todo, index) => <ToDoListItem key={index} {...todo} />)
}
return (
<div>
<table>
<ToDoListHeader />
<tbody>
{/* {this.renderItems()} */}
</tbody>
</table>
</div>
);
}
Share
Improve this question
edited Jul 25, 2017 at 9:10
kind user
41.9k8 gold badges68 silver badges78 bronze badges
asked Jul 24, 2017 at 11:33
Diego OrianiDiego Oriani
1,8975 gold badges23 silver badges36 bronze badges
2 Answers
Reset to default 7Well, you are getting error because you are defining the function like in a class, not in a function. Use a proper function declaration.
export const ToDoList = (props) => {
const renderItems = () => {
return _.map(this.props.todos, (todo, index) => <ToDoListItem key={index} {...todo} />)
}
return (
<div>
<table>
<ToDoListHeader />
<tbody>
{/* {this.renderItems()} */}
</tbody>
</table>
</div>
);
}
It would work fine, if only ToDoList
was a class, though.
renderItems = () => {
return _.map(this.props.todos, (todo, index) => <ToDoListItem key={index} {...todo} />)
}
Your varian will work with es6 classes.
本文标签: javascriptReactSyntax error Unexpected tokenexpected Stack Overflow
版权声明:本文标题:javascript - React — Syntax error: Unexpected token, expected ; - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740925917a2308804.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论