Skip to content

Commit

Permalink
move hooks before early return
Browse files Browse the repository at this point in the history
  • Loading branch information
Gengar-i committed Oct 18, 2023
1 parent 8d41b16 commit 669150b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/bundle/ui-dev/src/modules/common/popup/popup.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,22 @@ const Popup = ({
noCloseBtn,
extraClasses,
}) => {
const modalRef = useRef(null);

useEffect(() => {
document.body.classList.toggle(CLASS_MODAL_OPEN, isVisible);
document.body.classList.toggle(CLASS_NON_SCROLLABLE, isVisible);

if (isVisible) {
showPopup();
modalRef.current.addEventListener('hidden.bs.modal', onClose);
}
}, [isVisible]);

if (!isVisible) {
return null;
}

const modalRef = useRef(null);
const modalClasses = createCssClassNames({
'c-popup modal fade': true,
'c-popup--no-header': noHeader,
Expand Down Expand Up @@ -79,16 +90,6 @@ const Popup = ({
);
}, [hidePopup, closeBtnLabel, noCloseBtn]);

useEffect(() => {
document.body.classList.toggle(CLASS_MODAL_OPEN, isVisible);
document.body.classList.toggle(CLASS_NON_SCROLLABLE, isVisible);

if (isVisible) {
showPopup();
modalRef.current.addEventListener('hidden.bs.modal', onClose);
}
}, [isVisible]);

return (
<div ref={modalRef} className={modalClasses} tabIndex={hasFocus ? -1 : undefined}>
<div className={`modal-dialog c-popup__dialog ${MODAL_SIZE_CLASS[size]}`} role="dialog">
Expand Down

0 comments on commit 669150b

Please sign in to comment.