I am using react hooks to fetch an api and show the list of NBA players first and last name. Fetching API is successful as it can be shown in log but it's not displaying the names.
Free API I used:https://www.balldontlie.io/
//react component to fetch and show data
import { useCallback, useEffect, useState } from "react";
function App() {
const [data, setData] = useState([]);
const refreshData = useCallback(() => {
fetch("https://www.balldontlie.io/api/v1/players")
.then((res) => res.json())
.then((data) => {
setData(data);
console.log(data);
});
}, []);
useEffect(() => {
refreshData();
}, []);
return (
<div>
<h1>My player</h1>
<ul>
{Object.values(data).map((item) => (
<li key={item.id}>
{item.first_name} {item.last_name}
</li>
))}
</ul>
</div>
);
}
export default App;