Skip to content

Instantly share code, notes, and snippets.

@kingisaac95
Created December 5, 2017 17:32
Show Gist options
  • Save kingisaac95/2ab9931c52cc5240a528a89c85be8227 to your computer and use it in GitHub Desktop.
Save kingisaac95/2ab9931c52cc5240a528a89c85be8227 to your computer and use it in GitHub Desktop.
Fetch and render
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