Files
lcbp3/frontend/providers/query-provider.tsx
T
admin 11984bfa29
CI Pipeline / build (push) Failing after 12m41s
Build and Deploy / deploy (push) Failing after 2m44s
260322:1648 Correct Coresspondence / Doing RFA / Correct CI
2026-03-22 16:48:12 +07:00

32 lines
1.1 KiB
TypeScript

// File: providers/query-provider.tsx
'use client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import { useState } from 'react';
export default function QueryProvider({ children }: { children: React.ReactNode }) {
// สร้าง QueryClient instance เพียงครั้งเดียวต่อ request
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
queries: {
// ข้อมูลจะถือว่า "สดใหม่" (Fresh) เป็นเวลา 1 นาที
staleTime: 60 * 1000,
// จำนวนครั้งที่จะลองใหม่ถ้า Request ล้มเหลว
retry: 1,
refetchOnWindowFocus: false,
},
},
})
);
return (
<QueryClientProvider client={queryClient}>
{children}
<ReactQueryDevtools initialIsOpen={false} buttonPosition="bottom-right" />
</QueryClientProvider>
);
}