mirror of
https://github.com/mosh-hamedani/game-hub.git
synced 2026-05-21 12:14:32 +02:00
39 lines
767 B
TypeScript
39 lines
767 B
TypeScript
|
|
import { Text } from "@chakra-ui/react";
|
||
|
|
import React, { useEffect, useState } from "react";
|
||
|
|
import apiClient from "../services/api-client";
|
||
|
|
|
||
|
|
interface Game {
|
||
|
|
id: number;
|
||
|
|
name: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
interface FetchGamesResponse {
|
||
|
|
count: number;
|
||
|
|
results: Game[];
|
||
|
|
}
|
||
|
|
|
||
|
|
const GameGrid = () => {
|
||
|
|
const [games, setGames] = useState<Game[]>([]);
|
||
|
|
const [error, setError] = useState("");
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
apiClient
|
||
|
|
.get<FetchGamesResponse>("/xgames")
|
||
|
|
.then((res) => setGames(res.data.results))
|
||
|
|
.catch((err) => setError(err.message));
|
||
|
|
});
|
||
|
|
|
||
|
|
return (
|
||
|
|
<>
|
||
|
|
{error && <Text>{error}</Text>}
|
||
|
|
<ul>
|
||
|
|
{games.map((game) => (
|
||
|
|
<li key={game.id}>{game.name}</li>
|
||
|
|
))}
|
||
|
|
</ul>
|
||
|
|
</>
|
||
|
|
);
|
||
|
|
};
|
||
|
|
|
||
|
|
export default GameGrid;
|