我有以下呈现一系列组件的组件。但是,我下载了React 16.2,并尝试使用片段而不是div,但是出现以下错误:
Error in ./src/containers/answers.js Syntax error: Unexpected token (24:5) 22 | 23 | return ( > 24 | <> | ^ 25 | {AnswersCard} 26 | </> 27 | )
当片段应该能够替换React 16.2中的div时,为什么会出现此错误?
question ? AnswersCard = ( question.answers.sort(function(a,b) { return (a.count < b.count) ? 1 : ((b.count > a.count) ? -1 : 0)} ).map(answer => <Answer key={answer.id} answer={answer} questionId={question.id} /> )) : AnswersCard = ( <p>Loading...</p> ) return ( <> {AnswersCard} </> ) } }
按照该文件,语法<></>不是所有工具的支持,他们鼓励您使用<React.Fragment>,而不是
<></>
<React.Fragment>
查看有关片段语法支持的 本 文档