user9207458
user9207458

Reputation:

React Native app won't fetch api data

My React Native app won't fetch or get api data. It will not console log data or even an error. I've tried using fetch and axios.

fetch method:

    export default class List extends React.Component {
      commponentDidMount() {
        fetch(URL)
        .then((response) => response.json())
        .then((responseData) => {
          console.log(responseData);
        })
        .catch(error => {
            console.log(error);
        });
      }
    }

axios method:

    export default class List extends React.Component {
      commponentDidMount() {
        axios.get(URL)
        .then(function (response) {
          console.log(response);
        })
        .catch(function (error) {
          console.log(error);
        });
      } 
    }

I'm not sure what the problem is and I can't find a solution online.

Upvotes: 0

Views: 1319

Answers (1)

Seyha
Seyha

Reputation: 323

Please do check spelling function componentDidMount And try below sample code I have.

componentDidMount() {
  let URL = `https://...`;

  fetch(URL)
  .then(res => res.json())
  .then(res => {
      console.log('response:', res.data);
  });
}

Hope it will help.

Upvotes: 1

Related Questions