Skip to content

Instantly share code, notes, and snippets.

@okbel
Last active November 21, 2017 01:35
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 okbel/dd7a2f9d8983bf750ed4c0f67136749b to your computer and use it in GitHub Desktop.
Save okbel/dd7a2f9d8983bf750ed4c0f67136749b to your computer and use it in GitHub Desktop.
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