All files / src/features/transaction/hooks use-optimized-transactions.ts

85.71% Statements 6/7
100% Branches 0/0
66.66% Functions 2/3
85.71% Lines 6/7

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                2x   15x 15x 15x       15x               15x          
import { useCallback, useMemo } from 'react';
import { isEqual } from '../utils/memo-utils';
import type { Transaction } from '../components/transaction-table';
 
/**
 * Custom hook to optimize transaction data handling
 * Uses react-fast-compare for deep equality checks to prevent unnecessary re-renders
 */
export const useOptimizedTransactions = (transactions: Transaction[]) => {
  // Memoize the transactions array to prevent unnecessary re-renders
  const memoizedTransactions = useMemo(() => {
    console.log('🧠 Memoizing transactions array');
    return transactions;
  }, [transactions]);
 
  // Create a function to check if two transactions are equal
  const areTransactionsEqual = useCallback(
    (prev: Transaction, next: Transaction) => {
      return isEqual(prev, next);
    },
    []
  );
 
  // Return memoized values
  return {
    transactions: memoizedTransactions,
    areTransactionsEqual,
  };
};