2021-09-24 16:47:45 +09:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
function App (props) {
|
|
|
|
const uuid = props;
|
|
|
|
const [data, setData] = useState({ hits: [] });
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const fetchData = async () => {
|
2021-09-24 17:43:07 +09:00
|
|
|
let result = null;
|
|
|
|
try {
|
|
|
|
result = await axios('https://api.ashcon.app/mojang/v2/user/' + uuid.uuid);
|
|
|
|
setData(result.data);
|
|
|
|
} catch (err) {
|
|
|
|
result = 404;
|
|
|
|
setData(result);
|
|
|
|
}
|
2021-09-24 16:47:45 +09:00
|
|
|
};
|
|
|
|
fetchData();
|
|
|
|
}, []);
|
|
|
|
if (data === undefined){
|
|
|
|
console.log("[Minecraft: UUID to player's name] データの取得に失敗しました。 / Failed to retrieve data.")
|
2021-09-24 17:43:07 +09:00
|
|
|
return <>取得中...</>
|
2021-09-24 16:47:45 +09:00
|
|
|
}else {
|
2021-09-24 17:43:07 +09:00
|
|
|
if (data === 404) {
|
2021-09-24 19:06:26 +09:00
|
|
|
return <>404</>
|
2021-09-24 17:43:07 +09:00
|
|
|
} else {
|
|
|
|
return (
|
2021-09-24 19:06:26 +09:00
|
|
|
<>{data.username.toString()}</>
|
2021-09-24 17:43:07 +09:00
|
|
|
)
|
|
|
|
}
|
2021-09-24 16:47:45 +09:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|