React Native

React Native Networking & API

fetch API, axios, async/await, error handling, API integration, AbortController

20 gespreksvragen·
Mid-Level
1

What is the native JavaScript method for making HTTP requests in React Native?

Antwoord

fetch is the native API built into JavaScript and React Native for making HTTP requests. It returns a Promise and allows handling GET, POST, PUT, DELETE requests without external dependencies. Unlike axios, fetch is available natively without installing any package.

2

What does the fetch() method return when an HTTP request fails with a 404 or 500 code?

Antwoord

fetch() always resolves the Promise successfully as long as the network request completes, even for HTTP error codes like 404 or 500. You need to check response.ok or response.status manually to detect HTTP errors. fetch() only rejects the Promise for actual network errors like no connection.

3

What is the main advantage of axios over fetch for HTTP requests?

Antwoord

axios automatically transforms JSON data into JavaScript objects and handles HTTP error codes by rejecting the Promise. With fetch, you need to call response.json() manually and check response.ok. axios also offers interceptors, simplified cancellation, and better default timeout handling.

4

What is the correct syntax for sending JSON data with fetch in POST?

5

How does async/await simplify HTTP request handling compared to chained Promises?

+17 gespreksvragen

Beheers React Native voor je volgende gesprek

Krijg toegang tot alle vragen, flashcards, technische tests, code review-oefeningen en gespreksimulatoren.

Begin gratis