1

using Fetch API with ReactJS to get list of movies however I get this issue. Can someone help with this

 fetch("https://reactnative.dev/movies.json", {
      mode: "no-cors", // 'cors' by default
    })
      .then((response) => response.json())
      .then((json) => {
        console.log(json);
      });

get this error enter image description here

Nick Parsons
  • 45,728
  • 6
  • 46
  • 64
Jerry Seigle
  • 417
  • 4
  • 12
  • 2
    The API endpoint is protected by CORS, which means it will only allow a certain number of domains to make requests to it. Consider using a different API. Using "no-cors" will give back an opaque response, but won't give back meaningful data you can do stuff with. – Nick Parsons Feb 21 '21 at 00:19
  • What other API would you recommend. I seem to get a CORS issue with fetch and Axios – Jerry Seigle Feb 21 '21 at 00:31
  • It depends on the type of data that you want to get back. If it's movie data I'm sure there are plenty of APIs out there that would have this information. Otherwise, if you just want an API so you can test your fetch, you can use one of the APIs provided here: https://jsonplaceholder.typicode.com/ – Nick Parsons Feb 21 '21 at 00:36

1 Answers1

-1

Quoted By MDN:

by using no-cors JavaScript may not access any properties of the resulting Response.

if you use are no-cors to bypass the CORS policy, that's not the right way.

PS-PARSA
  • 932
  • 5
  • 15