overleaf/services/web/frontend/js/shared/hooks/use-deep-compare-effect.js
Timothée Alby 2cab7059ee Merge pull request #6717 from overleaf/ta-ds-deep-compare-memo
Use Deep Comparison for RootFolder Effects

GitOrigin-RevId: fd4dd523f131799eccd5909a7fd42ec7c985ca4e
2022-02-16 11:40:03 +00:00

13 lines
372 B
JavaScript

import { useEffect, useRef } from 'react'
import _ from 'lodash'
export default function useDeepCompareEffect(callback, dependencies) {
const ref = useRef()
return useEffect(() => {
if (_.isEqual(dependencies, ref.current)) {
return
}
ref.current = dependencies
callback()
}, dependencies) // eslint-disable-line react-hooks/exhaustive-deps
}