41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { useEffect, useState } from 'react';
|
||
import { Config } from './conf/config';
|
||
import { Card } from 'react-daisyui';
|
||
|
||
const App = () => {
|
||
const [apiResponse, setApiResponse] = useState<{
|
||
date_with_time: string,
|
||
text: string
|
||
}|null>(null);
|
||
|
||
// Загрузка данных с сервера
|
||
useEffect(() => {
|
||
|
||
fetch(`${Config.API_URL}/api`, {
|
||
headers: {
|
||
'Accept': 'application/json',
|
||
'Content-Type': 'application/json'
|
||
},
|
||
method: 'GET'
|
||
})
|
||
.then(async (response) => {
|
||
setApiResponse(await response.json())
|
||
})
|
||
.catch((error) => {
|
||
console.log('Ошибка при получении данных с api:', error);
|
||
alert("Ошибка при получении данных с api");
|
||
})
|
||
}, []);
|
||
|
||
return (
|
||
<div className='flex items-center justify-center absolute inset-0'>
|
||
<Card className="flex flex-col gap-2 border-[2px] items-center justify-center border-primary rounded-md p-6" style={{ width: '50vw', height: '200px' }}>
|
||
<h1>Шаблон приложения Fast API</h1>
|
||
<p>Время: {(apiResponse?.date_with_time) ? new Date(apiResponse?.date_with_time).toISOString() : "Нет данных по времени"}, Текст: {apiResponse?.text}</p>
|
||
</Card>
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default App;
|