reactjs - 使用 React 返回,出现语法错误?
问题描述
这是我第一次使用 React,我对语法感到困惑。在 Sublime Text 中,我在以下代码中返回后不断收到左括号错误,说明没有闭包,但是我显然在该文本字符串的末尾附近有它。
return (
<>
<section className="jumbotron jumbotron-fluid text-center">
<div className="container py-5">
<h1 className="display-4">Recipes for every occasion</h1>
<p className="lead text-muted">
We’ve pulled together our most popular recipes, our latest
additions, and our editor’s picks, so there’s sure to be something
tempting for you to try.
</p>
</div>
</section>
<div className="py-5">
<main className="container">
<div className="text-right mb-3">
<Link to="/recipe" className="btn custom-button">
Create New Recipe
</Link>
</div>
<div className="row">
{recipes.length > 0 ? allRecipes : noRecipe}
</div>
<Link to="/" className="btn btn-link">
Home
</Link>
</main>
</div>
</>
);
}
}
export default Recipes;
</> 中的反斜杠之后的代码似乎搞砸了,之后的所有内容都与字符串颜色相同。
我在这里想念什么?
解决方案
您的 Sublime Text JSX 荧光笔可能太旧了,不支持该<>
语法。
任何一个:
- 更新荧光笔(Package Control 中可能有更好的荧光笔)
- 对片段使用长格式
<React.Fragment>...</React.Fragment>
语法。
推荐阅读
- r - 如何根据R中的不同数据框选择一些列
- java - Spring Boot @Scheduled 方法创建 @Scope(request) 的实例
- php - Laravel 雄辩,基于 Column 值创建集合
- python - 我如何以某种方式转置熊猫数据框,其中我只需要两列,一列用于标题
- ios - CallKit 屏幕在响铃时位于应用程序 UI 后面
- here-api - HERE API:如何检查(纬度,经度)是否属于交叉点?
- reactjs - 我如何验证对象内部的对象是的?
- asp.net-core - 除非注销,否则登录用户将永远不会再次看到登录页面。Asp.net 核心(2.1 或 2.2 或 3.0)
- android - 如何强制 Firestore Recycler Adapter 加载实时数据而不是从缓存中
- javascript - 为什么 mongoose 查询结果对象在新版本中如此冗长?