Javascript 简单反应问题

Javascript 简单反应问题,javascript,reactjs,Javascript,Reactjs,在处理js的一小段代码时遇到问题,我不断地得到错误: 未能编译 ./src/App.js 第81:9行:应为赋值或函数调用,但看到的是表达式没有未使用的表达式 Search for the keywords to learn more about each error. This error occurred during the build time and cannot be dismissed. 代码如下: function TaskList() { const deadlines

在处理js的一小段代码时遇到问题,我不断地得到错误:

未能编译 ./src/App.js 第81:9行:应为赋值或函数调用,但看到的是表达式没有未使用的表达式

Search for the keywords to learn more about each error.
This error occurred during the build time and cannot be dismissed.
代码如下:

function TaskList() {
  const deadlines = [
    { title: "wash the dishes!"},
    { title: "take out the trash!" },
    { title: "walk the dog!"},
  ];

  return (
    <div style={{ padding: "30px" }}>
      {deadlines.map((task) => {
        <>
          <a>{task.title}</a>
        </>
      })}
    </div>
  );
}
函数任务列表(){
常数截止日期=[
{标题:“洗碗!”},
{标题:“倒垃圾!”},
{标题:“遛狗!”},
];
返回(
{截止日期.map((任务)=>{
{task.title}
})}
);
}

您只需在
映射
回调中
返回
您的JSX片段:

function TaskList() {
  const deadlines = [
    { title: "wash the dishes!"},
    { title: "take out the trash!" },
    { title: "walk the dog!"},
  ];

  return (
    <div style={{ padding: "30px" }}>
      {deadlines.map((task) => {
        return (
          <>
            <a>{task.title}</a>
          </>
        );
      })}
    </div>
  );
}
函数任务列表(){
常数截止日期=[
{标题:“洗碗!”},
{标题:“倒垃圾!”},
{标题:“遛狗!”},
];
返回(
{截止日期.map((任务)=>{
返回(
{task.title}
);
})}
);
}

您需要从map方法内部返回jsx

function TaskList() {
  const deadlines = [
    { title: "wash the dishes!"},
    { title: "take out the trash!" },
    { title: "walk the dog!"},
  ];

  return (
    <div style={{ padding: "30px" }}>
      {deadlines.map((task) => {
        return ( // return the jsx
         <>
           <a>{task.title}</a>
         </>
        );
      })}
    </div>
  );
}
函数任务列表(){
常数截止日期=[
{标题:“洗碗!”},
{标题:“倒垃圾!”},
{标题:“遛狗!”},
];
返回(
{截止日期.map((任务)=>{
return(//返回jsx
{task.title}
);
})}
);
}