Skip to content

Commit bc91861

Browse files
montezumekodiakhq[bot]
authored andcommitted
fix(collapsible-motion): do not set to null on rerender (#1043)
1 parent df0bdf7 commit bc91861

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/components/collapsible-motion/collapsible-motion.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const createClosingAnimation = (height, minHeight) =>
3636

3737
const useToggleAnimation = (isOpen, toggle, minHeight) => {
3838
const nodeRef = React.useRef();
39+
const animationRef = React.useRef(null);
3940
const prevIsOpen = usePrevious(isOpen);
4041

4142
React.useEffect(
@@ -65,16 +66,14 @@ const useToggleAnimation = (isOpen, toggle, minHeight) => {
6566
? { height: 'auto' }
6667
: { height: getMinHeight(minHeight), overflow: 'hidden' };
6768

68-
let animation = null;
69-
7069
// if state has changed
7170
if (typeof prevIsOpen !== 'undefined' && prevIsOpen !== isOpen) {
72-
animation = isOpen
71+
animationRef.current = isOpen
7372
? createOpeningAnimation(nodeRef.current.clientHeight, minHeight)
7473
: createClosingAnimation(nodeRef.current.clientHeight, minHeight);
7574
}
7675

77-
return [animation, containerStyles, handleToggle, nodeRef];
76+
return [animationRef.current, containerStyles, handleToggle, nodeRef];
7877
};
7978

8079
const CollapsibleMotion = props => {

0 commit comments

Comments
 (0)