pankod/refine

View on GitHub
packages/core/src/hooks/deepMemo/index.tsx

Summary

Maintainability
A
0 mins
Test Coverage
import React, { useMemo } from "react";
import { useMemoized } from "@hooks/memoized";

/**
 * Hook that memoizes the given dependency array and checks the consecutive calls with deep equality and returns the same value as the first call if dependencies are not changed.
 * @internal
 */
export const useDeepMemo = <T,>(
  fn: () => T,
  dependencies: React.DependencyList,
): T => {
  const memoizedDependencies = useMemoized(dependencies);

  const value = useMemo(fn, memoizedDependencies);

  return value;
};