-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deepcompare column prop to avoid endless loop
- Loading branch information
1 parent
0344088
commit 21ee389
Showing
9 changed files
with
96 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import isEqualWith from 'lodash.isequalwith'; | ||
import isFunction from 'lodash.isfunction'; | ||
import { useEffect, useRef } from 'react'; | ||
import type { DependencyList, EffectCallback } from 'react'; | ||
|
||
const depsEqual = (aDeps: DependencyList, bDeps: DependencyList = []) => { | ||
return isEqualWith(aDeps, bDeps, (a, b) => { | ||
if (isFunction(a) && isFunction(b) && a.toString() === b.toString()) { | ||
return true; | ||
} | ||
}); | ||
}; | ||
|
||
const useDeepFnCompareEffect = (effect: EffectCallback, deps: DependencyList) => { | ||
const ref = useRef<DependencyList>(); | ||
const signalRef = useRef<number>(0); | ||
|
||
if (!depsEqual(deps, ref.current)) { | ||
ref.current = deps; | ||
signalRef.current += 1; | ||
} | ||
|
||
useEffect(effect, [signalRef.current]); | ||
}; | ||
|
||
export default useDeepFnCompareEffect; |