I'm working on a project with lots of anti-patterns, and what I saw is IIFE around multiple useEffects, here is what I have:
condition &&
(() => {
useEffect(() => {
const calOffsetTimeout = setTimeout(() => {
calcOffsetWidth();
}, 150);
return () => {
clearTimeout(calOffsetTimeout);
};
}, [menuWidth.isExpanded, pdfWrapperRef.current]);
useEffect(() => {
calcOffsetWidth();
}, [pdfWrapperRef, desiredScale, zooming]);
useEffect(() => {
calcOffsetWidth();
return () => pdf && pdf.destroy();
}, [pdf]);
useEffect(() => {
window.addEventListener('resize', calcOffsetWidth);
return () => {
window.removeEventListener('resize', calcOffsetWidth);
};
}, []);
})();
It's working, but the downside is that I can't debug a single thing inside this iife function. I would like to know how bad or good it is to wrap logic (especially hooks) into iife. What i've tried is to add condition inside the deps arrays, but there is too much logic in the project and everything stops working, so it is not the right decision.