我目前正在觀看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」不是函數 –