{ "status_code": "100", "Section1_name": "Members", "Section1_count": 108, "Section2_name": "Countries", "Section2_count": 60, "Section3_name": "Offices", "Section3_count": 112, "Section4_name": "Teams", "Section4_count": 2950 }
Create a local storage variable and assign your API response to that variable by setting it.
Doc link:
https://reactnative.dev/docs/network
Code for reference:
import React, { useEffect, useState } from 'react';
import { ActivityIndicator, FlatList, Text, View } from 'react-native';
export default App = () => {
const [isLoading, setLoading] = useState(true);
const [data, setData] = useState([]);
const getMovies = async () => {
try {
const response = await fetch('https://reactnative.dev/movies.json');
const json = await response.json();
setData(json.movies);
} catch (error) {
console.error(error);
} finally {
setLoading(false);
}
}
useEffect(() => {
getMovies();
}, []);
return (
<View style={{ flex: 1, padding: 24 }}>
{isLoading ? <ActivityIndicator/> : (
<FlatList
data={data}
keyExtractor={({ id }, index) => id}
renderItem={({ item }) => (
<Text>{item.title}, {item.releaseYear}</Text>
)}
/>
)}
</View>
);
};