How it works...
In step 4, we sent the request to the API. We use the fetch method to make the request. The first parameter is a string with the URL of the endpoint, while the second parameter is a configuration object. For this request, the only option we need to define is the request method to GET, but we can also use this object to define headers, cookies, parameters, and many other things.
We are also using async/await syntax to wait on the response and finally set it on the state. If you prefer, you could, of course, use promises for this purpose instead.
Also, note how we are using an arrow function here to properly handle the scope. This will automatically set the correct scope when this method is assigned to the onPress callback. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access