What is Networking
-
Many mobile apps need to load resources from a remote URL. You may want to make a POST/GET request to a REST API
Examples
GET (Fetching movies from REST endpoint and display as list)
|
![]() 1. import react hooks useEffect, useState 2. Taken 2 variables isLoading: Tracks whether the data is still being fetched. Initially set to true and switched to false when loading is complete data: Stores the list of movies fetched from the API 3. fetch() = HTTP GET. response.json(): Converts the response into a JSON object. setData(): Sets the movies into data variable setLoading(false): Stops the loading indicator once data is fetched. 4. Use useEffect hook. useEffect ensures function is called only once after re-render 5. 2 View blocks Outer View: wraps for consistency and padding Inner View: Contains the FlatList and its header, & in FlatList data recieved from REST endpoint is rendered 6. FlatList explanation data: The array of items to render. keyExtractor: Provides a unique key for each item, which is critical for performance. renderItem: A function that renders each item in the list. |