reactjs - ReactJs Newbie 期待一个赋值或函数调用,而是看到一个表达式 no-unused-expressions
问题描述
所有,我在 react js 应用程序中收到以下错误。我是 React 的新手,并试图创建一个示例应用程序并遇到这个问题:期望一个赋值或函数调用,而是看到一个表达式 no-unused-expressions..任何关于发生了什么的指针.....示例代码
import React, { useState } from "react";
import "./App.css";
import Post from "./Post";
function App() {
const [posts, setPosts] = useState([
{
username: "kmangal",
caption: "wow this is working and cool",
imageUrl: "{require('./images/antoers.jpg')}",
},
{
username: "ROHINI",
caption: "Rohie wow this is working and cool",
imageUrl: "{require('./images/antoers.jpg')}",
},
{
username: "GEETA",
caption: "GEETA wow this is working and cool",
imageUrl: "{require('./images/antoers.jpg')}",
},
]);
return (
<div className="App">
<div className="app_header">
<img className="app_header" src={require("./images/logo.png")} alt="" />
</div>
<h1>hellow this is khemlall</h1>
{posts.map((post) => {
<Post username={post.username} />;
})}
<Post
username="kmangal"
caption="wow this is working and cool"
imageUrl={require("./images/antoers.jpg")}
/>
<Post
username="Rohini"
caption="rohini mrry khemlall"
imageUrl={require("./images/prot1.png")}
/>
<Post
username="geeta"
caption="she is my sisster"
imageUrl={require("./images/psot2.jpg")}
/>
</div>
);
}
export default App;
解决方案
{posts.map((post) => {
<Post username={post.username} />;
})}
此地图功能不返回任何内容。在以下位置添加 return 语句:
{posts.map((post) => {
return <Post username={post.username} />;
})}
或者通过删除大括号来做箭头函数的缩短版本
{posts.map((post) => (
<Post username={post.username} />
))}
推荐阅读
- javascript - 使用 JSONP 进行跨域请求
- python - 如何使用熊猫经纬度数据快速计算距离?
- .net - EventViewer 中的 .net 异常不包含消息部分
- r - shinyFeedback 不适用于 shinyWidgets 的 autonumericInput 函数
- typescript - 打字稿原始类型
- php - 尝试使用递归,最终得到意大利面条代码
- python - 如何在python中使用比较器对对象数组进行排序
- php - PHP/HTML 联系表单的问题
- functional-programming - 我在 f-sharp 中有一个相互递归问题
- python - Python Pandas中DataFrame中的值聚合?