diff --git a/src/hooks/useShowTransition.ts b/src/hooks/useShowTransition.ts index 81f4dccb6..2c46755d5 100644 --- a/src/hooks/useShowTransition.ts +++ b/src/hooks/useShowTransition.ts @@ -13,18 +13,18 @@ export default ( const [isClosed, setIsClosed] = useState(!isOpen); const closeTimeoutRef = useRef(); // СSS class should be added in a separate tick to turn on CSS transition. - const [hasAsyncOpenClassName, setHasAsyncOpenClassName] = useState(false); + const [hasOpenClassName, setHasOpenClassName] = useState(isOpen && noOpenTransition); if (isOpen) { setIsClosed(false); - setHasAsyncOpenClassName(true); + setHasOpenClassName(true); if (closeTimeoutRef.current) { window.clearTimeout(closeTimeoutRef.current); closeTimeoutRef.current = undefined; } } else { - setHasAsyncOpenClassName(false); + setHasOpenClassName(false); if (!isClosed && !closeTimeoutRef.current) { closeTimeoutRef.current = window.setTimeout(() => { @@ -39,7 +39,6 @@ export default ( } } - const hasOpenClassName = hasAsyncOpenClassName || (isOpen && noOpenTransition); const isClosing = Boolean(closeTimeoutRef.current); const shouldRender = isOpen || isClosing; const transitionClassNames = buildClassName( diff --git a/src/util/arePropsShallowEqual.ts b/src/util/arePropsShallowEqual.ts index 3ed791023..0568e8269 100644 --- a/src/util/arePropsShallowEqual.ts +++ b/src/util/arePropsShallowEqual.ts @@ -1,4 +1,8 @@ export default function arePropsShallowEqual(currentProps: AnyLiteral, newProps: AnyLiteral) { + if (currentProps === newProps) { + return true; + } + const currentKeys = Object.keys(currentProps); const currentKeysLength = currentKeys.length; const newKeysLength = Object.keys(newProps).length; @@ -7,5 +11,16 @@ export default function arePropsShallowEqual(currentProps: AnyLiteral, newProps: return false; } - return currentKeys.every((prop) => currentProps[prop] === newProps[prop]); + if (currentKeysLength === 0) { + return true; + } + + for (let i = 0; i < currentKeysLength; i++) { + const prop = currentKeys[i]; + if (currentProps[prop] !== newProps[prop]) { + return false; + } + } + + return true; }