问答详情
源自:3-1 React 属性

NameCard改成函数之后还是编译失败

根据老师的代码改成了

class NameCard = (props) => {

const {name,number,isHuman,tags}=props

return(

<div className="alert alert-success">

<h4 className="alert-heading">{name}</h4>

<ul>

<li>电弧:{number}</li>

<li>{isHuman?'人类':'外星人'}</li>

</ul>

<p>

{tags.map((tag, index)=>(<span key={index}>

{tag}

</span>))}

</p>

</div>

)

}

但是保存之后还是编译失败

Failed to compile

./src/components/NameCard.js
 Line 3:  Parsing error: Unexpected token, expected "{"

 1 | import React from 'react'
 2 |
> 3 | class NameCard = (props) => {
   |                ^
 4 | const {name,number,isHuman,tags}=props
 5 | return(
 6 | <div className="alert alert-success">

This error occurred during the build time and cannot be dismissed.


提问者:roylawxi 2019-08-13 15:45

个回答

  • theland
    2019-08-28 13:23:17

    class NameCard = (props) => {

    const NameCard = (props)=>{

  • gelimin
    2019-08-20 10:58:28

    请问你导出了吗 export default NameCard