Skip to content

Instantly share code, notes, and snippets.

@maecapozzi
Created December 9, 2017 17:07
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 maecapozzi/0ac2472a03ae4ce6ee8548f0c657e076 to your computer and use it in GitHub Desktop.
Save maecapozzi/0ac2472a03ae4ce6ee8548f0c657e076 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import './App.css'
import axios from 'axios'
class App extends Component {
constructor () {
super()
this.state = {
username: ''
}
this.handleClick = this.handleClick.bind(this)
}
handleClick () {
axios.get('https://api.github.com/users/maecapozzi')
.then(response => this.setState({username: response.data.name}))
}
render () {
return (
<div className='button__container'>
<button className='button' onClick={this.handleClick}>Click Me</button>
<p>{this.state.username}</p>
</div>
)
}
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment