Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
Add Comment
Please, Sign In to add comment