If you need to detect changes in width within an element, you can create a custom function that specifically checks for this:
const checkWidthChange = function($element, callback) {
let lastDimensions = $element.getBoundingClientRect();
const observer = new ResizeObserver(function() {
const currentDimensions = $element.getBoundingClientRect();
if(currentDimensions.width !== lastDimensions.width && currentDimensions.height === lastDimensions.height)
callback();
lastDimensions = currentDimensions;
});
observer.observe($element);
}
You can then implement it like so:
checkWidthChange(layout.current, setLayout);