Skip to content

Commit

Permalink
some useEffect bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
night committed May 30, 2024
1 parent 0323b08 commit e1e2df9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/modules/emote_menu/components/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ export default function Button({
]);

useEffect(() => {
const callback = () => {
function callback() {
setLoaded(true);
};
}

if (loaded || emoteMenuViewStore.isLoaded()) {
callback();
return;
return null;
}

emoteMenuViewStore.once('updated', callback);
const removeListener = emoteMenuViewStore.once('updated', callback);
return () => {
removeListener();
};
}, []);

useEffect(() => {
Expand Down
11 changes: 5 additions & 6 deletions src/modules/emote_menu/hooks/HorizontalResize.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export default function useHorizontalResize({boundingQuerySelector, handleRef, r
}

React.useEffect(() => {
if (handleRef.current == null) {
return undefined;
const currentRef = handleRef.current;
if (currentRef == null) {
return null;
}

function handleWindowResize() {
Expand All @@ -52,14 +53,12 @@ export default function useHorizontalResize({boundingQuerySelector, handleRef, r

handleWindowResize();

handleRef.current.addEventListener('mousedown', handleResizeStart);
currentRef.addEventListener('mousedown', handleResizeStart);
document.addEventListener('mouseup', handleResizeEnd);
window.addEventListener('resize', handleWindowResize);

return () => {
if (handleRef.current != null) {
handleRef.current.removeEventListener('mousedown', handleResizeStart);
}
currentRef.removeEventListener('mousedown', handleResizeStart);
document.addEventListener('mouseup', handleResizeEnd);
window.removeEventListener('resize', handleWindowResize);
};
Expand Down

0 comments on commit e1e2df9

Please sign in to comment.