All files / src/hooks use-store-debugging.ts

100% Statements 12/12
83.33% Branches 5/6
100% Functions 3/3
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38              2x 21x         20x       20x   20x   13x     13x     12x     11x   11x 11x        
import { useEffect } from 'react';
import StoreDebugger from '@/store/debug';
 
/**
 * Hook to initialize Zustand store debugging
 * Add this to your main App component to enable comprehensive logging
 */
export const useStoreDebugging = (enabled?: boolean) => {
  useEffect(() => {
    // Determine if debugging should be enabled
    // In test environment, use process.env.NODE_ENV for compatibility with existing tests
    // In browser environment, use import.meta.env.MODE
    const nodeEnv =
      typeof process !== 'undefined'
        ? process.env.NODE_ENV
        : import.meta.env.MODE;
    const shouldEnable =
      enabled !== undefined ? enabled : nodeEnv === 'development';
 
    if (!shouldEnable) return;
 
    console.log('🚀 [Zustand] Store debugging enabled');
 
    // Log initial state
    StoreDebugger.logAllStores();
 
    // Subscribe to changes
    StoreDebugger.subscribeToChanges();
 
    // Log when stores are initialized
    console.log('✅ [Zustand] All stores initialized and ready');
 
    return () => {
      console.log('🛑 [Zustand] Store debugging disabled');
    };
  }, [enabled]);
};