Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

React - basic API fetch

0 votes
3 views
added Mar 1 in React by LC Marshal Lieutenant (16,990 points)
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;

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...