I am not too sure if I worded the title accurately, but I am essentially using an API in my react native expo app and I am having trouble called elements from my Api.
Th structure of my Api json file is as follows:
{
"links": [
// content
],
"assets": [
{
"id": "1"
"name": "Joe"
}
]
}
My React Native code is as follows:
const App = () => {
const [data, setData] = useState([]);
useEffect(() => {
fetchData();
}, []);
const fetchData = async () => {
try {
const response = await axios.get(API_URL);
setData(response.data);
}
catch (error) {
console.error('Error fetching data:', error);
}
};
return (
<View style = {styles.container}>
<Text style = {styles.title}>Making API Requests</Text>
<FlatList
data={data}
keyExtractor={item => String(item.id)}
renderItem = {({item}) => (
<View style = {styles.item}>
<Text>{item.name}</Text>
</View>
)}
/>
</View>
);
};
Based on the above, I am trying to call item.name
from assets. However, there is no data being populated.
How can I fix this so that I can call data from the assets part of the api?
Thank You in Advance! 🙂