Skip to content

A simpler fetch #20

@Albadylic

Description

@Albadylic

Rather than try/catch & async/await:

try {
let response = await fetch(url);
let json = await response.json();
return json;
} catch (error) {
console.log(error);
}

You could add a .then to your fetch to process the json

fetch(url)
  .then(response => response.json())
  .then(data => setUserData({ name: data.name, avatar_url: data.avatar_url })).then(() => setCurrentPage('hula'));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions