import React, { useMemo, useState } from "react";
import { useQuery } from "react-query";
import axios from "axios";
import {
Button,
Center,
Flex,
Heading,
Icon,
Input,
Table,
Thead,
Tbody,
Tfoot,
Tr,
Th,
Td,
TableCaption,
} from "@chakra-ui/react";
import { FaUserCircle, FaArrowAltCircleRight } from "react-icons/fa";
import { Link } from "react-router-dom";
const Statistic = ({ type, name, players }) => {
const ranking = useQuery(
`statistic ${type} ${name}`,
async () => {
const { data } = await axios.get(`/api/statistics/${type}/${name}`);
return data;
},
{
placeholderData: [],
}
);
const playerDict = useMemo(() => {
return Object.assign({}, ...players.data.map((x) => ({ [x.id]: x.name })));
}, players);
return (
<>
Player | Rank | Value |
---|---|---|
{playerDict[x.playerId]} | {x.rank} | {x.value} |