Skip to content

Commit

Permalink
fix: use Object.is to judge two value isChange (alibaba#1627)
Browse files Browse the repository at this point in the history
* fix(useWhyDidYouUpdate): use Object.is to determines whether the two values have changed

* fix(useTrackedEffect): use Object.is to determines whether the two values have changed
  • Loading branch information
hchlq authored May 16, 2022
1 parent a8c2f8a commit 6024d66
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/hooks/src/useTrackedEffect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const diffTwoDeps = (deps1?: DependencyList, deps2?: DependencyList) => {
//If deps1 is defined, we iterate over deps1 and do comparison on each element with equivalent element from deps2
//As this func is used only in this hook, we assume 2 deps always have same length.
return deps1
? deps1.map((_ele, idx) => (deps1[idx] !== deps2?.[idx] ? idx : -1)).filter((ele) => ele >= 0)
? deps1
.map((_ele, idx) => (!Object.is(deps1[idx], deps2?.[idx]) ? idx : -1))
.filter((ele) => ele >= 0)
: deps2
? deps2.map((_ele, idx) => idx)
: [];
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/src/useWhyDidYouUpdate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function useWhyDidYouUpdate(componentName: string, props: IProps)
const changedProps: IProps = {};

allKeys.forEach((key) => {
if (prevProps.current[key] !== props[key]) {
if (!Object.is(prevProps.current[key], props[key])) {
changedProps[key] = {
from: prevProps.current[key],
to: props[key],
Expand Down

0 comments on commit 6024d66

Please sign in to comment.