Skip to content

Commit

Permalink
Testing live
Browse files Browse the repository at this point in the history
  • Loading branch information
EmoruwaTolu committed Apr 9, 2024
1 parent 2d56377 commit 88298c2
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions prem-data/src/pages/player-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,38 @@ function PlayerPage() {
const [season, setSeason] = useState();
const [seasonLinkedList, setSeasonLinkedList] = useState();

// useEffect(() => {
// if (player) {
// axios.get(`/player/${player.playerName}`)
// .then(response => {
// setPlayerInfo(response.data);
// setSeason(arrayToCircularLinkedList(response.data).head)
// setSeasonLinkedList(arrayToCircularLinkedList(response.data))
// console.log(response.data[response.data.length - 1].name);
// })
// .catch(error => {
// console.error("Error fetching player data:", error);
// });
// }
// }, [player]);
useEffect(() => {
if (player) {
axios.get(`/player/${player.playerName}`)
.then(response => {
setPlayerInfo(response.data);
setSeason(arrayToCircularLinkedList(response.data).head)
setSeasonLinkedList(arrayToCircularLinkedList(response.data))
console.log(response.data[response.data.length - 1].name);
})
.catch(error => {
console.error("Error fetching player data:", error);
});
}
}, [player]);
if (player) {
async function fetchData() {
try {
const response = await fetch(`/player/${player.playerName}`);
const data = await response.json();
setPlayerInfo(data);
const linkedList = await arrayToCircularLinkedList(data);
setSeason(linkedList.head);
setSeasonLinkedList(linkedList);
console.log(data[data.length - 1].name);
} catch (error) {
console.error("Error fetching player data:", error);
}
}
fetchData();
}
}, [player]);

if (playerInfo.length === 0) {
return <p>Loading player data...</p>;
Expand Down

0 comments on commit 88298c2

Please sign in to comment.