mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
d959dbc236
[web] Shared React hooks JS to TS conversion GitOrigin-RevId: 0ccdebff236c7424b1a73cd7d6646a9d01a20eb1
16 lines
403 B
TypeScript
16 lines
403 B
TypeScript
import { useEffect, useRef } from 'react'
|
|
import _ from 'lodash'
|
|
|
|
export default function useDeepCompareEffect<T>(
|
|
callback: () => void,
|
|
dependencies: T[]
|
|
) {
|
|
const ref = useRef<T[]>()
|
|
return useEffect(() => {
|
|
if (_.isEqual(dependencies, ref.current)) {
|
|
return
|
|
}
|
|
ref.current = dependencies
|
|
callback()
|
|
}, dependencies) // eslint-disable-line react-hooks/exhaustive-deps
|
|
}
|