Dylan Steck Dylan Steck - 1 year ago 241
React JSX Question

How to query JSON data from REST API in React Native

I want to query through some data from NewsAPI in React Native and have no idea how to do so and none of the tutorials I've seen have helped. Thanks!

Answer Source

Check out the Docs on Networking from React Native... I'm using Fetch in our production apps.

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

MDN Fetch API Guide

 .then(res => {
    if (res.ok) return res.json())
    else throw new Error(res)
 .then(json => {
   for (var key in json) {
     // now you can parse it by calling json[key]
 .catch(error => console.log(error)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download