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>
>Solution :
repositoryData is an array of RepositoryResponse which contains one filed data which is a Repository.
repositoryData.map({data} => {return (
<p> {data.name} </p>
<p>{data.owner.login}</p>
<p> {data.html_url}</p>)
})