React官方文档里React理念的demo代码问题

新手上路,请多包涵

1.出现问题,不知道哪里错了?

Uncaught SyntaxError: Inline Babel script: Unexpected token, expected , (68:33)
  66 |                                 <td colSpan="2"><ProductCategoryRow category={item[0].category} /></td>
  67 |                                 </tr>   
> 68 |                                  {item.map((line) => {
     |                                  ^
  69 |                                             return  (<ProductRow name={line.name} price={line.price} key={line.name}/>)}
  70 |                                         )}
  71 |                                         
    at Parser.pp$5.raise (babel.js:17994)
    at Parser.pp.unexpected (babel.js:15337)
    at Parser.pp.expect (babel.js:15325)
    at Parser.pp$3.parseParenAndDistinguishExpression (babel.js:17368)
    at Parser.pp$3.parseExprAtom (babel.js:17263)
    at Parser.parseExprAtom (babel.js:20637)
    at Parser.pp$3.parseExprSubscripts (babel.js:17048)
    at Parser.pp$3.parseMaybeUnary (babel.js:17028)
    at Parser.pp$3.parseExprOps (babel.js:16958)
    at Parser.pp$3.parseMaybeConditional (babel.js:16935)


2.出错局部的代码:

class ProductTable extends React.Component {
            constructor(props) {
                super(props);
            }

            render() {
                return (
                    <table>
                    <thead>
                        <tr>
                            <th><span className="title">Name</span></th>
                            <th><span className="title">Price</span></th>
                        </tr>
                        </thead>
                        <tbody>
                            {this.props.categoryArray.map((item,index) => {
                            return (
                                <tr key={index}>
                                <td colSpan="2"><ProductCategoryRow category={item[0].category} /></td>
                                </tr>   
                                 {item.map((line) => {
                                            return  (<ProductRow name={line.name} price={line.price} key={line.name}/>)}
                                        )}
                                        
                            )})}
                            
                            </tbody>
                    </table>
                )
            }
        }

3.文档链接https://doc.react-china.org/d...

阅读 2.4k
1 个回答

babel了没有?
/加一个文件.bablerc

{
  "presets": [
    "es2015",
    "stage-0",
    "react"
  ]
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题