File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed
packages/core/src/components/panel-stack2 Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import * as React from "react";
19
19
import { CSSTransition , TransitionGroup } from "react-transition-group" ;
20
20
21
21
import { Classes , DISPLAYNAME_PREFIX , type Props } from "../../common" ;
22
+ import { usePrevious } from "../../hooks" ;
22
23
23
24
import type { Panel } from "./panelTypes" ;
24
25
import { PanelView2 } from "./panelView2" ;
@@ -103,12 +104,9 @@ export const PanelStack2: PanelStack2Component = <T extends Panel<object>>(props
103
104
( ) => ( isControlled ? propsStack . slice ( ) . reverse ( ) : localStack ) ,
104
105
[ localStack , isControlled , propsStack ] ,
105
106
) ;
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" ;
112
110
113
111
const handlePanelOpen = React . useCallback (
114
112
( panel : T ) => {
You can’t perform that action at this time.
0 commit comments