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;};
@internal in the comment here means that this is only internal use and is not exposed in the public API and has a comment explaining what this hook is about:
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.
Going back to code snippet above, there is only dependency here
import { useRef } from "react";import isEqual from "lodash/isEqual";/** * Hook that memoizes the given value with deep equality. * @internal */export const useMemoized = <T = unknown>(value: T): T => { const ref = useRef(value); if (!isEqual(ref.current, value)) { ref.current = value; } return ref.current;};
This is also another internal function and is found to be using isEqual imported from “lodash/isEqual”.
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.