Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Property 'name' does not exist on type 'RepositoryResponse[]'. Typescript

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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>)
})

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading