I'm trying to make the side buttons in the carousel(3rd slide) change based on the inner slide container size resizing with media query. I've got it working except for one bug. When I resize back from smaller responsive, the button doesn't change, until I resize again (smaller or bigger but on the same media query)
- Site to reproduce error: https://9wk9h.csb.app/
- The Full Code: https://codesandbox.io/s/my-portfolio-2021-9wk9h
This is the block of code used in the file src/Components/AboutComponents/AboutCarousel.js:
useLayoutEffect(() => {
if (slideIndex === slideIndexes.fun) {
const handleResize = debounce(() => {
setIsScreenResized(!isScreenResized);
console.log('isScreenResized changed =', isScreenResized);
console.log('---------------------')
}, 100);
window.addEventListener('resize', handleResize, false);
return () => {
window.removeEventListener('resize', handleResize, false);
}
}
},[slideIndex, slideIndexes, hobbyTabIdSelected, isScreenResized, setIsScreenResized]);
See the following use case below to reproduce the issue:
