Answers for "fetch javascript react"

-1

using componentdidmount with fetch

import React, { Component } from 'react';
class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: null,
    };
  }
  componentDidMount() {
    fetch('https://api.mydomain.com')
      .then(response => response.json())
      .then(data => this.setState({ data }));
  }
  ...
}
export default App;
Posted by: Guest on April-11-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language