I am using React Native, it is not calling the value of first_name from the API that I am using, which is this https://reqres.in/
import React, { useState, useEffect } from "react";
import { StyleSheet, Text, View, FlatList } from "react-native";
import axios from "axios";
export default function App() {
const [user, setUser] = useState({hits: []});
useEffect(async () => {
const result = await axios('https://reqres.in/api/users');
setUser(result.data);
});
render() {
return (
<View>
<FlatList
data={user}
renderItem={(userItem) => (
<View>
<Text>{`${userItem.first_name} ${userItem.last_name}`}</Text>
</View>
)}
/>
</View>
);
}
}
const styles = StyleSheet.create({});
With these modifications it should work. As a reference, I leave you this link where you can see the response schema of axios (the data returned by the server is inside
data
), also how to use the renderItem prop of the react-native FlatList, where I added the appropriate destructure.