-
Notifications
You must be signed in to change notification settings - Fork 15
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
Changes from 1 commit
20c5b50
2075384
0f6b9da
129e8bd
e3b2630
653d013
9478add
cb51729
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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')) { | ||
unsetModalContext(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check if you can call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, the code does look more logical. |
||
} | ||
}, [isOpen]); | ||
|
||
|
@@ -71,7 +66,7 @@ function PureModal(props: Props) { | |
|
||
function unsetModalContext() { | ||
document.removeEventListener('keydown', handleEsc); | ||
removeClassBody(); | ||
document.body.classList.remove('body-modal-fix'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тобто було гарно одною функцією, а стало тепер інлайново в двох місцях? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Згоден, не вірно зрозумів спочатку. |
||
setX(null); | ||
setY(null); | ||
setDeltaX(0); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут проблема, що isClassBody має неправильне значення?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зрозумів, що useMemo може зробити не вірно при перерендерах кожного разу тай лишні перестворення функції.