From 6024d66cb4a5c32922d01a8a19c11caf8b69a0c5 Mon Sep 17 00:00:00 2001 From: huangcheng Date: Mon, 16 May 2022 19:16:09 +0800 Subject: [PATCH] fix: use Object.is to judge two value isChange (#1627) * 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 --- packages/hooks/src/useTrackedEffect/index.ts | 4 +++- packages/hooks/src/useWhyDidYouUpdate/index.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/hooks/src/useTrackedEffect/index.ts b/packages/hooks/src/useTrackedEffect/index.ts index b36470b948..07ec5a7bac 100644 --- a/packages/hooks/src/useTrackedEffect/index.ts +++ b/packages/hooks/src/useTrackedEffect/index.ts @@ -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) : []; diff --git a/packages/hooks/src/useWhyDidYouUpdate/index.ts b/packages/hooks/src/useWhyDidYouUpdate/index.ts index d7531b5dff..197f0ddc83 100644 --- a/packages/hooks/src/useWhyDidYouUpdate/index.ts +++ b/packages/hooks/src/useWhyDidYouUpdate/index.ts @@ -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],