How to add the response of an API call in Reactjs?

Asked

Viewed 56 times

0

I am creating a doubt generated from another that I had done before. The link to the first question is: Adding an array within an array?

I created this Arrow Function to be able to put the code in the variable table and return it later.

I would like to place the data of your respective commits in each repository.

I tried to do as below by giving a console.log. But it returns me the amount of existing repositories.

Can someone give me a north of how to add the information in this case?

    reposTable = () => {

  let table = []


  for (let i = 0; i < this.state.reponame.length; i++) {
    let repo = []
    let repourl = []

    table.push(
      <div class="accordion" id="accordionExample">{repo}{repourl}
        <div class="card">
          <div class="card-header" id="headingOne">
          <div className="row">
            <div className="col-sm-4"><b>Repository Name:</b><p> {this.state.reponame[i].name}</p></div>
            <div className="col-sm-6"><b>Link:</b> <a href={this.state.reponame[i].html_url} target="_blank" rel="noopener noreferrer">{this.state.reponame[i].html_url}
                            </a></div>
            <div className="col-sm"> <button class="btn btn-link" type="button" data-toggle="collapse" data-target={`#`+this.state.reponame[i].name} aria-expanded="true" aria-controls={"collapseOne"}>
                Commits 
              </button></div>
          </div>

            <h2 class="mb-0">
            </h2>
          </div>




          <div id={this.state.reponame[i].name} class="collapse" aria-labelledby="headingOne" data-parent="#accordionExample">
            <div class="card-body">
              {}
              Commit: {console.log(this.state.commits)}
            </div>
          </div>
        </div>

        </div>
    )


}
return table
}
  • How does that answer come?

  • It has been repeating the number of Positorios that I have according to print: https://imgur.com/NoO4SiM Inside, it has the commits of each repository: https://imgur.com/nSx8UuD

  • Complicated your question has to provide an example of how it comes and how you want it to stay

  • As it comes, you say the console.log(this.state.commits) response? if that’s what I put in the prints. Actually, I wanted to use the answer within the <div class="card-body">, as I used for the repository name just above ( this.state.reponame[i].name). But since the answer comes with an array and within it several arrays, I don’t know how to take the information and add it to the "Commit" field. Thank you very much for your reply.

  • what you put in the prints has the arrays need to open one of those arrays to see its contents ...

  • every project this way needs to have a layout and if you don’t know imagine we try to help !!!

  • I am putting the answer: img: https://imgur.com/Nihzkmo

Show 2 more comments

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.