how to make a github api using react

Solutions on MaxInterview for how to make a github api using react by the best coders in the world

showing results for - "how to make a github api using react"
Clovis
11 Apr 2016
1    class GitHubSearch extends React.Component {
2       constructor(props){ 
3         super(props); 
4          this.state = { 
5           username: '',
6           userrepo: '',
7          };
8       }
9
10       getUser(username) {
11          return fetch(`https://api.github.com/users/${username}`)
12          .then(response => response.json())
13          .then(response => {
14            return response;
15           })
16      }
17
18       getUserRepo(userrepo) {
19         return fetch(`https://api.github.com/users/${username}/repos`)
20         .then(response => response.json())
21         .then(response => {
22          return response;
23        })
24      }
25
26       async handleSubmit(e) {
27           e.preventDefault();
28           let user = await this.getUser(this.refs.username.value);
29           this.setState({ avatar_url: user.avatar_url,
30           username: user.login,
31           followers: user.followers,
32           following: user.following,
33            url: user.url,
34       });
35
36     let repo = await this.getUserRepo(this.refs.userrepo.value);
37        this.setState({ name: repo.name,
38        description: repo.description,
39        git_url: repo.git_url,
40        stargazers_count: repo.stargazers_count,
41        forks_count: repo.forks_count,
42        open_issues_count: repo.open_issues_count,
43        size: repo.size,
44
45     })
46
47  }
48
49     render() {
50       let user;
51       if(this.state.username) {
52          user = 
53          <div className="resultBadge">
54            <img src={this.state.avatar_url}/>
55            <p className="userInfo">
56             Username: <br/>
57             {this.state.username} 
58            </p> 
59            <p className="followerInfo">
60             {this.state.followers} Followers
61            </p>
62            <p className="followingInfo">
63              Following {this.state.following} users
64            </p>
65          </div>
66      }
67
68      let repo;
69        if(this.state.userrepo) {
70           repo =
71             <div className="repoResults">
72                <p>
73                  {this.state.name}
74               </p>
75             </div>
76         }
77
78           return (
79              <div className="GitHubSearch">
80                <header className="Search-header">
81                  <h1>Github User Search </h1>
82                </header>
83                <form onSubmit={e => this.handleSubmit(e)}>
84                   <input ref='username' type='text' placeholder='username' />
85               </form>
86               <p className="Search-intro">
87                  {user}
88               </p>
89      <p>
90        {repo}
91       </p>
92      </div>
93   );
94 }
95}
96
97
98ReactDOM.render(<GitHubSearch/>, document.getElementById('container'));
queries leading to this page
recipe app react with api githubreact api githubapi project in react js in githubfihub api reacthow to call github api in react projectusing github api with react class componentgithub api in react js examplehow to make github with reactcreate react app with github desktopgithub simple react apphow to implement github api to fetch data in reactjs and reduxhow to use github issue api in reactreact js api projects githubgithub create react appcreate react app with api github examplesimple react app with http githubusing github api on reactapi documentation in react js from githubreact github api appgithub api reactgithub react apihow to acces github api in reacthow to use github issue api in react jshow to make a github api using reactgithub api example reactapi documentation example in react js githubreact js project with api integration githubgithub api example react javascriptgithubapi reactgithub api in react appgithub rest api react github api for reactapi integration in react js githubreact project github api react api service example githubsimple react app githubgithub api reactgithub basic react appapi react githubreact js github api examplereact api based project git hubhow to make with react to use github apihow to make call ti github api in reacthow to use github api javascript reactreact github apihow to deploy react app on githubreact github api examplegithub api react jsgithub api in react js github api react examplereact js github api apphow to get followers in github api using reactreact api project githubgithub gist api example reactreact app on githubgithub api with reactgithub user api reactgithub api fetching data of users 2c repositories 2c commits 2c issues in reduxgithub api react appraect js code for the application with api ontegrated githubhow to use github issue rest api in reactapi react git hubreact call github apiscall github api react jshow to make a github api using react