Skip to content

Commit

Permalink
refactor: implement review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
stropitek committed Jun 25, 2024
1 parent 5d0e8c2 commit cbf3061
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/core/src/components/panel-stack2/panelStack2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as React from "react";
import { CSSTransition, TransitionGroup } from "react-transition-group";

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

import type { Panel } from "./panelTypes";
import { PanelView2 } from "./panelView2";
Expand Down Expand Up @@ -103,12 +104,8 @@ export const PanelStack2: PanelStack2Component = <T extends Panel<object>>(props
() => (isControlled ? propsStack.slice().reverse() : localStack),
[localStack, isControlled, propsStack],
);
const stackLength = React.useRef<number>(stack.length);
// Adjust the direction in case the stack size has changed, controlled or uncontrolled
const direction = stack.length - stackLength.current < 0 ? "pop" : "push";
React.useEffect(() => {
stackLength.current = stack.length;
}, [stack]);
const prevStackLength = usePrevious(stack.length) ?? stack.length;
const direction = stack.length - prevStackLength < 0 ? "pop" : "push";

const handlePanelOpen = React.useCallback(
(panel: T) => {
Expand Down

0 comments on commit cbf3061

Please sign in to comment.