【发布时间】:2018-06-24 06:18:20
【问题描述】:
我正在为 reactJS 和 typescript 使用下面的代码。执行命令时出现以下错误。
我还添加了导入语句 导入'bootstrap/dist/css/bootstrap.min.css'; 在 Index.tsx 中。
有没有办法解决这个问题?
npm start
client/src/Results.tsx
(32,21): Missing "key" prop for element.
文件如下“Results.tsx”
import * as React from 'react';
class Results extends React.Component<{}, any> {
constructor(props: any) {
super(props);
this.state = {
topics: [],
isLoading: false
};
}
componentDidMount() {
this.setState({isLoading: true});
fetch('http://localhost:8080/topics')
.then(response => response.json())
.then(data => this.setState({topics: data, isLoading: false}));
}
render() {
const {topics, isLoading} = this.state;
if (isLoading) {
return <p>Loading...</p>;
}
return (
<div>
<h2>Results List</h2>
{topics.map((topic: any) =>
<div className="panel panel-default">
<div className="panel-heading" key={topic.id}>{topic.name}</div>
<div className="panel-body" key={topic.id}>{topic.description}</div>
</div>
)}
</div>
);
}
}
export default Results;
【问题讨论】:
标签: node.js reactjs typescript