how to load api in react in javascript

Using Fetch API

index.tsx
function fetchData() {
    fetch('API URL')
        .then(response => response.json())
        .then(data => console.log(data))
        .catch(error => console.log(error))
}

fetchData();
188 chars
9 lines

Using Axios

index.tsx
import axios from 'axios';

function fetchData() {
    axios.get('API URL')
        .then(response => console.log(response.data))
        .catch(error => console.log(error))
}

fetchData();
190 chars
10 lines

gistlibby LogSnag