Choose the best reason why mobile apps connect to backend servers using APIs.
Think about how apps get updated information or save user data.
APIs allow apps to communicate with backend servers to get or send data securely. This is essential for dynamic content and user data management.
When a React Native app calls an API to get data, what should the UI show while waiting for the response?
Think about how apps keep users informed during slow network calls.
Showing a loading spinner or message informs users that data is being fetched, improving user experience.
Which lifecycle event is best to trigger an API call to fetch data when a screen appears?
Think about when the component is ready and mounted.
Using useEffect with an empty dependency array runs the API call once after the component mounts, ideal for initial data fetch.
You fetched user info from backend on Screen A. How do you pass this data to Screen B when navigating?
Think about how navigation libraries pass info between screens.
Passing data as parameters in navigation.navigate allows Screen B to receive and use the API data.
Given this code snippet, why does the fetch fail?
fetch('http://localhost:3000/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error))Think about what 'localhost' means on a mobile device.
On a mobile device, 'localhost' points to the device itself, not the development machine. The app cannot reach the backend server this way.