This commit is contained in:
grinikita
2024-12-14 12:32:32 +03:00
parent b997d670a0
commit 0ad224f04d
11 changed files with 191 additions and 32 deletions
+3 -24
View File
@@ -1,30 +1,9 @@
import React, { useEffect, useState } from 'react';
import React from 'react';
import Heading from '../../components/heading';
import { useGetListQuery } from '../../store/api';
const ListPage = (): React.ReactElement => {
const [error, setError] = useState<string>(null);
const [data, setData] = useState<Array<{ id: number; title: string; description: string }>>();
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
const handle = async () => {
setIsLoading(true);
try {
const res = await fetch('/api/list');
const data = await res.json();
if (res.ok) {
setData(data);
} else {
setError(data.message);
}
} catch (e) {
setError(e.message);
} finally {
setIsLoading(false);
}
};
handle();
}, []);
const { data, isLoading, error } = useGetListQuery(undefined);
return (
<>