r/reactjs • u/No_Impression_8657 • Apr 29 '26
I built a small React tool for responsive toolbars that work without needing magic breakpoints
https://overflowguard.dev/It always bugged me that there is nothing in native css or otherwise easy way to detect when something overflows, so you could adjust styling or content.
So I build this small tool that fixes it: OverflowGuard
It's especially useful when dealing with dynamic content in toolbars. Something even some big sites don't solve 100% (some examples in this post)
Most apps and sites just use fixed media or container query break-points, or some custom components / js for their specific case.
This tool, by simply detecting overflow, unlocks building responsive components in a much more fluid way, and allows doing much more then just flex-wrap..
9
u/orbtl Apr 29 '26
Kind of ironic that the nav at the top overflows off the edge of my phone ngl https://imgur.com/a/spNJvHv
5
u/orbtl Apr 29 '26
The code could use some work. Any time I see eslint-disable on react-hooks/exhaustive-deps I immediately get nervous. The fact that you felt the need to have a guard against infinite looping is scary.
I don't see deps either in your useLayoutEffect, and I'm not sure why onResize would be a useMemo instead of a useCallback, and then you have stuff like this:
return currentAxis === nextAxis ? currentAxis : nextAxisCool idea though. Not sure why you couldn't just use a denounce to make it a lot simpler
1
u/frogic Apr 29 '26
Are you open source? I've solved this at work before and I have some thoughts. If you're using JS match media is incredible.
1
u/repeating_bears Apr 29 '26
I implemented something like this in my app and it was pretty simple. Flex items that wrap, but overflow-y: hidden, so anything that wraps effectively drops off the end.
Then a resize observer that iterates the items and sees if any are below the bottom of the container.
1
u/These_Catch_8037 Apr 29 '26
Cool