Created
December 20, 2017 09:06
-
-
Save TondaHack/4e5fbdb791b9142626de86c157e1c63f to your computer and use it in GitHub Desktop.
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, { Component } from 'react'; | |
import 'whatwg-fetch' | |
import './App.css'; | |
import UserList from './UserList'; | |
class App extends Component { | |
constructor(props){ | |
super(props) | |
this.state = { | |
value: '', | |
userList: [] | |
} | |
} | |
search = () => { | |
const { value } = this.state; | |
fetch(`https://api.github.com/search/users?q=${value}`) | |
.then(res=>res.json()) | |
.then((data) => { | |
this.setState({ | |
userList: data.items | |
}) | |
}) | |
} | |
changeButton = (e) => { | |
this.setState({value: e.target.value}) | |
} | |
render() { | |
const { value, userList } = this.state; | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<input value={value} onChange={this.changeButton} /> | |
<button onClick={this.search}> Search</button> | |
</header> | |
<div> | |
<UserList userList={userList} /> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment