属性“名称”类型“RepositoryResponse[]”上不存在。打字稿
我正在尝试从 GitHub API 获取数据,但出现错误:界面中不存在 API 中的值。 API URL:https://api.github.com/repos/facebook/react
interface Repository {
name: string;
avatar_url: string;
html_url: string;
owner : {
login: string;
}
}
interface RepositoryResponse {
data: Repository
}
const [repositoryData,setRepositoryData] = useState<RepositoryResponse[]>([]);
//Component
<p> {repositoryData.name} </p>
<p> {repositoryData.owner.login} </p>
<p> {repositoryData.html_url} </p>
I am trying to fetch data from the GitHub API, but give me the error that values from the API does not exist in the interface.
API URL : https://api.github.com/repos/facebook/react
interface Repository {
name: string;
avatar_url: string;
html_url: string;
owner : {
login: string;
}
}
interface RepositoryResponse {
data: Repository
}
const [repositoryData,setRepositoryData] = useState<RepositoryResponse[]>([]);
//Component
<p> {repositoryData.name} </p>
<p> {repositoryData.owner.login} </p>
<p> {repositoryData.html_url} </p>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
repositoryData 是一个 RepositoryResponse 数组,其中包含一个存储库的字段数据。
repositoryData is an array of RepositoryResponse which contains one filed data which is a Repository.