Skip to content

Commit

Permalink
fix: resolve infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
monicawheeler committed May 16, 2024
1 parent 59c8132 commit afe1e93
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/sage-react/lib/Drawer/Drawer.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { Modal } from '../Modal';
Expand Down Expand Up @@ -30,8 +30,10 @@ export const Drawer = ({
size,
title,
}) => {
const prevExpandedRef = useRef();

useEffect(() => {
if (onExpandChange) {
if (onExpandChange && prevExpandedRef.current !== expanded) {
// Trigger outwards that a change to expanded was detected
onExpandChange(expanded ? DRAWER_START_EXPAND : DRAWER_START_COLLAPSE);

Expand All @@ -40,6 +42,7 @@ export const Drawer = ({
onExpandChange(expanded ? DRAWER_END_EXPAND : DRAWER_END_COLLAPSE);
}, 750);
}
prevExpandedRef.current = expanded;
}, [expanded, onExpandChange]);

const classNames = classnames(
Expand Down

0 comments on commit afe1e93

Please sign in to comment.