fix: Remove console.log spam from useAnalytics hook
Problem:
- 7,521+ console messages flooding the console
- 4 console.log statements in useAnalytics hook
- Logging on every render and query state change
Root Cause:
useAnalytics hook had debug console.log statements:
1. Hook called log (every render)
2. Fetching from API log (every query)
3. Query state log (every state change)
4. Returning log (every render)
With multiple analytics hooks running (overview, revenue, orders, etc.),
this created thousands of console messages.
Solution:
Removed all 4 console.log statements from useAnalytics hook.
Before:
console.log(`[useAnalytics:${endpoint}] Hook called:`, ...);
console.log(`[useAnalytics:${endpoint}] Fetching from API...`);
console.log(`[useAnalytics:${endpoint}] Query state:`, ...);
console.log(`[useAnalytics:${endpoint}] Returning:`, ...);
After:
(all removed)
Result:
✅ Clean console
✅ No performance impact from logging
✅ Hook still works perfectly
✅ React Query devtools available for debugging
Files Modified:
- useAnalytics.ts: Removed 4 console.log statements
This commit is contained in:
@@ -14,12 +14,9 @@ export function useAnalytics<T>(
|
|||||||
) {
|
) {
|
||||||
const { period, useDummy } = useDashboardPeriod();
|
const { period, useDummy } = useDashboardPeriod();
|
||||||
|
|
||||||
console.log(`[useAnalytics:${endpoint}] Hook called:`, { period, useDummy });
|
|
||||||
|
|
||||||
const { data, isLoading, error, refetch } = useQuery({
|
const { data, isLoading, error, refetch } = useQuery({
|
||||||
queryKey: ['analytics', endpoint, period, additionalParams],
|
queryKey: ['analytics', endpoint, period, additionalParams],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
console.log(`[useAnalytics:${endpoint}] Fetching from API...`);
|
|
||||||
const params: AnalyticsParams = {
|
const params: AnalyticsParams = {
|
||||||
period: period === 'all' ? undefined : period,
|
period: period === 'all' ? undefined : period,
|
||||||
...additionalParams,
|
...additionalParams,
|
||||||
@@ -32,13 +29,6 @@ export function useAnalytics<T>(
|
|||||||
retry: false, // Don't retry failed API calls (backend not implemented yet)
|
retry: false, // Don't retry failed API calls (backend not implemented yet)
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`[useAnalytics:${endpoint}] Query state:`, {
|
|
||||||
isLoading,
|
|
||||||
hasError: !!error,
|
|
||||||
hasData: !!data,
|
|
||||||
useDummy
|
|
||||||
});
|
|
||||||
|
|
||||||
// When using dummy data, never show error or loading
|
// When using dummy data, never show error or loading
|
||||||
// When using real data, show error only if API call was attempted and failed
|
// When using real data, show error only if API call was attempted and failed
|
||||||
const result = {
|
const result = {
|
||||||
@@ -48,12 +38,6 @@ export function useAnalytics<T>(
|
|||||||
refetch, // Expose refetch for retry functionality
|
refetch, // Expose refetch for retry functionality
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(`[useAnalytics:${endpoint}] Returning:`, {
|
|
||||||
hasData: !!result.data,
|
|
||||||
isLoading: result.isLoading,
|
|
||||||
hasError: !!result.error
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user