Created
December 5, 2017 17:32
-
-
Save kingisaac95/2ab9931c52cc5240a528a89c85be8227 to your computer and use it in GitHub Desktop.
Fetch and render
This file contains hidden or 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 request from 'axios'; | |
import Name from './Name.jsx'; | |
class WorkShop extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
user: {}, | |
name: '', | |
description: '', | |
ingredients: [], | |
procedures: [] | |
}; | |
} | |
getUser(username) { | |
request.get(`https://api.github.com/users/${username}`) | |
.then(res => { | |
this.setState({ user: res.data }); | |
}); | |
} | |
clicked() { | |
alert('I\'ve been clicked!'); | |
} | |
render() { | |
const data = { | |
bio: this.state.user.bio, | |
avatar: this.state.user.avatar_url, | |
handleClick: this.clicked | |
}; | |
return ( | |
<div> | |
<h1>Welcome to our workshop.</h1> | |
<div> | |
<button onClick={() => this.getUser('kingisaac95')}>Get user</button> | |
</div> | |
<Name | |
data={data} | |
/> | |
</div> | |
); | |
} | |
} | |
export default WorkShop; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment