how to use fetch in js in javascript

index.tsx
fetch('https://api.example.com/data')
    .then(response => {
        if(!response.ok) {
            throw new Error('Network response was not ok');
        }
        return response.json();
    })
    .then(data => {
        console.log(data);
    })
    .catch(error => {
        console.error('There was a problem with the fetch operation:', error);
    });
361 chars
14 lines

related categories

gistlibby LogSnag