-
-
Save Tunji545/56e86b7e2497d12f83defb4c1f44f3a7 to your computer and use it in GitHub Desktop.
I am working on a simple app using github api to implement a search box which then print out the result of the search. I have been struggling to build the search box (GithubSearch.js) to detect the specific Github features and print it out. Someone should please continue from where I stopped and implement the said feature Thanks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
class GithubProfile extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
userName: {}, | |
isLoading: false | |
} | |
} | |
componentDidMount() { | |
this.setState({ | |
isLoading: true | |
}) | |
fetch("https://api.github.com/users/Tunji545") | |
.then(response => response.json()) | |
.then(data => { | |
this.setState({ | |
isLoading: false, | |
userName: data | |
}) | |
}); | |
} | |
render() { | |
// const results = this.state.isLoading ? "Loading..." : this.state.userName; | |
return ( | |
<div className="github-user"> | |
<img className="github-user_avatar" src="https://avatars0.githubusercontent.com/u/13945094?v=4" width="200" height="200" alt="Avatar" /> | |
<div className="github-user_info"> | |
<p>{this.props.userName}</p> | |
<p>{this.props.bio}</p> | |
</div> | |
</div> | |
) | |
} | |
} | |
export default GithubProfile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import GithubProfile from "./GithubProfile"; | |
import Form from "./GithubSearchForm"; | |
class Search extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
userName: {} | |
} | |
} | |
handleSearch(searchTerm) { | |
console.log(searchTerm) // I guess this is where I need help to implement. | |
} | |
render() { | |
return ( | |
<div> | |
<Form onSearch={this.handleSearch} /> | |
{this.state.userName ? <GithubProfile userName={this.state.userName.name} bio={this.state.userName.bio} /> : null} | |
</div> | |
) | |
} | |
} | |
export default Search; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
class Form extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
userInput: "" | |
} | |
this.handleSubmit = this.handleSubmit.bind(this); | |
} | |
handleSubmit(event) { | |
event.preventDefault(); | |
const {name, value} = event.target | |
this.setState({ | |
[name] : value | |
}) | |
this.props.onSearch(this.state.value); | |
} | |
render() { | |
return ( | |
<form onSubmit={this.handleSubmit} > | |
<p>Enter the username:</p> | |
<input type="text" name="userInput" value={this.state.value} /> | |
<button>GO!</button> | |
</form> | |
) | |
} | |
} | |
export default Form; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment