mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
a54b633726
[web] Parser backed file outline GitOrigin-RevId: 0825f4887ba4dae24a14dd1880d07b791d0b4cd9
18 lines
509 B
TypeScript
18 lines
509 B
TypeScript
import { DependencyList, useMemo, useRef } from 'react'
|
|
import { isEqual } from 'lodash'
|
|
|
|
function useDeepCompare(dependencies: DependencyList) {
|
|
const ref = useRef<DependencyList>([])
|
|
if (!isEqual(ref.current, dependencies)) {
|
|
ref.current = dependencies
|
|
}
|
|
return ref.current
|
|
}
|
|
|
|
export default function useDeepCompareMemo<T>(
|
|
factory: () => T,
|
|
dependencies: DependencyList
|
|
) {
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
return useMemo(factory, useDeepCompare(dependencies))
|
|
}
|