(url, {
+ queryKey: ['tasklist'],
+ placeholderData: keepPreviousData
+ });
if (!url) return null;
- if (!data && !error) {
+ if (isLoading) {
return (
diff --git a/frontend/src/hooks/useFetch.ts b/frontend/src/hooks/useFetch.ts
new file mode 100644
index 0000000000..cf1af6422e
--- /dev/null
+++ b/frontend/src/hooks/useFetch.ts
@@ -0,0 +1,15 @@
+import { UseQueryOptions, useQuery } from '@tanstack/react-query';
+
+export const useFetch = (
+ url?: string | null,
+ options?: UseQueryOptions
+) =>
+ useQuery({
+ queryKey: [url],
+ queryFn: () =>
+ url
+ ? fetch(url).then((res) => res.json())
+ : Promise.reject('No URL provided'),
+ enabled: !!url,
+ ...options
+ });