Skip to content

Instantly share code, notes, and snippets.

@carlosvillu
Created April 2, 2016 19:50
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 carlosvillu/3f473c58c8f267b39c7907db937959bc to your computer and use it in GitHub Desktop.
Save carlosvillu/3f473c58c8f267b39c7907db937959bc to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDom from 'react-dom';
import axios from 'axios';
class Header extends React.Component {
constructor() {
super()
debugger
this.state = {
name: '',
description: ''
};
}
getData() {
axios
.get('http://api.randomuser.me/')
.then(response => {
this.setState({
name: response.data.results[0].user.name.first,
description: response.data.results[0].user.gender
});
});
}
componentDidMount() {
debugger
this.getData();
}
render() {
return (
<div >
<h1 > {this.state.name} </h1>
<h2 > {this.state.description} </h2>
</div>
);
}
}
ReactDom.render( < Header / > , document.getElementById('root'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment