Skip to content

Instantly share code, notes, and snippets.

@TondaHack
Created December 20, 2017 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TondaHack/4e5fbdb791b9142626de86c157e1c63f to your computer and use it in GitHub Desktop.
Save TondaHack/4e5fbdb791b9142626de86c157e1c63f to your computer and use it in GitHub Desktop.
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