0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-12-23 04:30:11 +09:00
yude.jp/pages/components/Minecraft/PlayerName.js

38 lines
889 B
JavaScript
Raw Normal View History

2021-12-11 18:55:57 +09:00
// React
import React, { useState, useEffect } from 'react';
2021-12-11 18:55:57 +09:00
// Data fetching
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);
}
};
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 <>取得中...</>
}else {
2021-09-24 17:43:07 +09:00
if (data === 404) {
return <>404</>
2021-09-24 17:43:07 +09:00
} else {
return (
2021-09-24 19:08:39 +09:00
<>{data.username}</>
2021-09-24 17:43:07 +09:00
)
}
};
}
export default App;