当我使用"=>"为什么我在 React 组件类中得到"Unexpected token. Did you mean `{'>'}` or `>`?ts"-



我看过一些类似的Q&A,但还是看不懂。我是初学者。当我使用=>在React组件类中,它是不被识别的。所以我得到了"雇员">

ListEmployeeComponent:

class ListEmployeeComponent extends Component {
constructor(props) {
super(props);
this.state = {
employees: [],
};
}
render() {
return (
<div>
<h2 className="text-center">Employees List</h2>
<div className="row">
<table className="table table-striped taable-bordered">
<thead>
<tr>
<th>Employee First Name</th>
<th>Employee Last Name</th>
<th>Employee Email ID</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
this.state.employees.map((employee) => (
<tr key={employee.id}>
<td>{employee.firstname}</td>
<td>{employee.lastname}</td>
<td>{employee.emailId}</td>
</tr>
))
</tbody>
</table>
</div>
</div>
);
}
}
export default ListEmployeeComponent;

下面是错误的截图。请帮我解决这个问题或建议我什么,以便我能更好地理解它。

截图感谢您的宝贵时间。

jsx中的JS语句缺少花括号:

...
{this.state.employees.map((employee) => (
<tr key={employee.id}>
<td>{employee.firstname}</td>
<td>{employee.lastname}</td>
<td>{employee.emailId}</td>
</tr>
))}
...

最新更新