Skip to content

Commit

Permalink
performance fix (keeping track of event listeners a bit better)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Cohen committed Feb 10, 2024
1 parent c01d082 commit c0fe13f
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import classNames from 'classnames';

export function HeaderContainer({ setBlurBackground }: any) {
const unblurOverride = useRef(false);
const unblurListenerAdded = useRef(false);

return (
<div className="navbar flex items-center bg-base-100 shadow-md px-2 md:px-4 lg:px-5">
Expand All @@ -27,11 +28,15 @@ export function HeaderContainer({ setBlurBackground }: any) {
if (!unblurOverride.current) {
setBlurBackground((prev: Boolean) => !prev);
document.removeEventListener('click', unBlurBackground);
unblurListenerAdded.current = false;
} else {
unblurOverride.current = false;
}
};
document.addEventListener('click', unBlurBackground);
if (!unblurListenerAdded.current) {
document.addEventListener('click', unBlurBackground);
unblurListenerAdded.current = true;
}
}}
>
<svg
Expand Down

0 comments on commit c0fe13f

Please sign in to comment.