feat: add SWR for data fetching with optimistic updates

This commit is contained in:
Developer
2026-03-18 16:16:04 +08:00
parent bd99fc8e81
commit 1f51c330dd
5 changed files with 167 additions and 2 deletions
+21
View File
@@ -0,0 +1,21 @@
import { getRecords, getStats, getCategories, getRecurringBills } from './api';
// 全局 SWR 配置
export const swrConfig = {
refreshInterval: 0, // 默认不自动刷新
revalidateOnFocus: true,
revalidateOnReconnect: true,
dedupingInterval: 2000,
errorRetryCount: 3,
onError: (error) => {
console.error('SWR Error:', error);
},
};
// 数据获取器映射
export const fetchers = {
records: (month, type) => getRecords(month, type),
stats: (month) => getStats(month),
categories: () => getCategories(),
recurring: () => getRecurringBills(),
};