Last active
November 21, 2017 01:35
-
-
Save okbel/dd7a2f9d8983bf750ed4c0f67136749b to your computer and use it in GitHub Desktop.
This file contains 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 from 'react'; | |
class Component extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
data: [], | |
}; | |
} | |
handleRequest = () => { | |
fetch('/api') | |
.then(res => res.json) | |
.then(data => { | |
this.setState({ | |
data | |
}); | |
}); | |
} | |
render() { | |
console.log(this.state.data); | |
return ( | |
<div> | |
<button onClick={this.handleRequest}> | |
Get Data | |
</button> | |
</div> | |
); | |
} | |
} | |
export default Component; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment