Skip to content

Commit 0b4d5cb

Browse files
committed
refactor: implement review suggestions
1 parent 5d0e8c2 commit 0b4d5cb

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

packages/core/src/components/panel-stack2/panelStack2.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as React from "react";
1919
import { CSSTransition, TransitionGroup } from "react-transition-group";
2020

2121
import { Classes, DISPLAYNAME_PREFIX, type Props } from "../../common";
22+
import { usePrevious } from "../../hooks";
2223

2324
import type { Panel } from "./panelTypes";
2425
import { PanelView2 } from "./panelView2";
@@ -103,12 +104,9 @@ export const PanelStack2: PanelStack2Component = <T extends Panel<object>>(props
103104
() => (isControlled ? propsStack.slice().reverse() : localStack),
104105
[localStack, isControlled, propsStack],
105106
);
106-
const stackLength = React.useRef<number>(stack.length);
107-
// Adjust the direction in case the stack size has changed, controlled or uncontrolled
108-
const direction = stack.length - stackLength.current < 0 ? "pop" : "push";
109-
React.useEffect(() => {
110-
stackLength.current = stack.length;
111-
}, [stack]);
107+
const prevStackLength = usePrevious(stack.length) ?? stack.length;
108+
// const stackLength = React.useRef<number>(stack.length);
109+
const direction = stack.length - prevStackLength < 0 ? "pop" : "push";
112110

113111
const handlePanelOpen = React.useCallback(
114112
(panel: T) => {

0 commit comments

Comments
 (0)