Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remove class in body #85

Merged
merged 8 commits into from
Jul 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/react-pure-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,12 @@ function PureModal(props: Props) {
const [mouseOffsetY, setMouseOffsetY] = useState(0);

const { isOpen, onClose } = props;
const isClassBody = useMemo(() => document.body.classList.contains('body-modal-fix'), [isOpen]);

const removeClassBody = useCallback(() => {
document.body.classList.remove('body-modal-fix');
}, []);

useEffect(() => {
if (isOpen) {
open();
} else if (isClassBody) {
removeClassBody();
} else if (document.body.classList.contains('body-modal-fix')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут проблема, що isClassBody має неправильне значення?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зрозумів, що useMemo може зробити не вірно при перерендерах кожного разу тай лишні перестворення функції.

unsetModalContext();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if you can call close function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, the code does look more logical.

}
}, [isOpen]);

Expand Down Expand Up @@ -71,7 +66,7 @@ function PureModal(props: Props) {

function unsetModalContext() {
document.removeEventListener('keydown', handleEsc);
removeClassBody();
document.body.classList.remove('body-modal-fix');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тобто було гарно одною функцією, а стало тепер інлайново в двох місцях?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Згоден, не вірно зрозумів спочатку.

setX(null);
setY(null);
setDeltaX(0);
Expand Down