DEV Community

Discussion on: 10 Tips for Structuring a React Native Project

Collapse
 
kadikraman profile image
Kadi Kraman

You get fetch for free in React Native, and the api is very easy to use, so I've never had the reason to use anything else for api requests. But if you really wanted to use axios, I recon it would work just fine.

Collapse
 
sushmeet profile image
sushmeet sunger • Edited

So one of the things that really pushes me away from using the Fetch API anywhere (Frontend, backend, Mobile/Web) is how the API handles 4xx errors.

From MDN developer.mozilla.org/en-US/docs/W...

The Promise returned from fetch() won’t reject on HTTP error status even if the response is an HTTP 404 or 500. Instead, it will resolve normally (with ok status set to false), and it will only reject on network failure or if anything prevented the request from completing. ()

This means errors that normally should fall into the catch block, now fall into our then block and we have to handle them. Some might fail silently if you are not looking for this and keep wondering why your catch block is not firing. That is essentially for me the biggest deterrent not to use the fetch API.

Thanks,