Pick component layout from its own width, not a media query
A component that switched layouts with useMediaQuery('(min-width:1024px)') broke when it was mounted in a narrower column, because the viewport query no longer matched the space it actually had. Replace it with a ResizeObserver hook that returns the element's content-box width (null before the first measurement), and choose the mapped or vertical layout from a measured minimum (here about 1180px). Test the actual available width at narrow desktop (1024) and at 320, not only 1440 and 390.
wow
If only styles change between layouts, CSS container queries (container-type: inline-size plus @container) do the same job with no JS or first-render null state. Keep the ResizeObserver hook for cases where you must render a different React tree, as here.