我目前正在观看React Path @ PluralSight(这是很棒的方式),我正在经历两个组件的一些问题。为什么我的组件不能渲染?
我有这个组件称为作者,这是在这里:
class Authors extends React.Component {
constructor(props) {
super(props);
this.state = {
authors: []
};
}
componentDidMount() {
if (this.isMounted()){
this.setState({ authors: AuthorApi.getAllAuthors() });
}
}
render() {
return(
<div className="container">
<h1>Authors</h1>
<hr />
<AuthorList authors={this.state.authors} />
</div>
);
}
}
和组件AuthorList,这是在这里:
const AuthorList = (props) => {
const createAuthorRow = (author) => {
return(
<tr key={author.id}>
<td><a href={"/#authors/" + author.id}>{author.id}</a></td>
<td>{author.firstName} {author.lastName}</td>
</tr>
);
};
return(
<div>
<table className="table">
<thead>
<th>id</th>
<th>Name</th>
</thead>
<tbody>
{this.props.authors.map(createAuthorRow, this)}
</tbody>
</table>
</div>
);
};
的问题是,他们没有渲染!他们都在同一个文件中,不知何故,他们不会呈现。我曾尝试为每个文件制作单独的文件,但它们仍不会呈现。我错过了什么吗?
在chrome中打开您的控制台开发人员工具,并告诉我们到底发生了什么错误? – Fiido93
TypeError:“this.isMounted”不是函数 –