Spaces:
Running
Running
axeronis
perf: Implement React Query caching for faster navigation - Dashboard now uses React Query with 5min staleTime - Optimized QueryClient settings: staleTime=5min, gcTime=30min - Added SWR context and hooks (optional alternative) - Faster page transitions with cached data
4c90e6d Download frontend/contexts/SWRContext.tsx from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/frontend/contexts/SWRContext.tsx
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/frontend/contexts/SWRContext.tsx
-
curl -L -o SWRContext.tsx https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/frontend/contexts/SWRContext.tsx
1.56 kB
| 'use client' | |
| import { SWRConfig } from 'swr' | |
| import { api } from '@/lib/api' | |
| // Fetcher function for SWR using our axios instance | |
| const fetcher = async (url: string) => { | |
| const response = await api.get(url) | |
| return response.data | |
| } | |
| interface SWRProviderProps { | |
| children: React.ReactNode | |
| } | |
| export function SWRProvider({ children }: SWRProviderProps) { | |
| return ( | |
| <SWRConfig | |
| value={{ | |
| fetcher, | |
| // Revalidation settings for better UX | |
| revalidateOnFocus: false, // Don't refetch when window regains focus | |
| revalidateOnReconnect: true, // Refetch when network reconnects | |
| dedupingInterval: 5000, // Dedupe requests within 5 seconds | |
| errorRetryCount: 3, // Retry failed requests 3 times | |
| errorRetryInterval: 1000, // Wait 1 second between retries | |
| // Cache settings | |
| keepPreviousData: true, // Show stale data while fetching new | |
| // Performance optimization | |
| refreshInterval: 0, // Disable auto-refresh (manual control) | |
| refreshWhenHidden: false, // Don't refresh when tab is hidden | |
| refreshWhenOffline: false, // Don't refresh when offline | |
| // Fallback for initial loading | |
| suspense: false, // Don't use React Suspense | |
| }} | |
| > | |
| {children} | |
| </SWRConfig> | |
| ) | |
| } | |