Reduce workspace rerenders during explorer resize

This commit is contained in:
Mohamed Boudra
2026-04-22 22:18:11 +07:00
parent b133285f6d
commit 1f8f8e4036
3 changed files with 81 additions and 3 deletions
@@ -16,3 +16,25 @@ export function useContainerWidth(): {
width,
};
}
/**
* Tracks only whether a container is narrower than a threshold.
*/
export function useContainerWidthBelow(threshold: number): {
onLayout: (e: LayoutChangeEvent) => void;
isBelow: boolean;
} {
const [isBelow, setIsBelow] = useState(true);
return {
onLayout: useCallback(
(e: LayoutChangeEvent) => {
const nextIsBelow = e.nativeEvent.layout.width < threshold;
setIsBelow((currentIsBelow) =>
currentIsBelow === nextIsBelow ? currentIsBelow : nextIsBelow,
);
},
[threshold],
),
isBelow,
};
}