Description
React Container Query is a React library for responsive components that react to the size of their container rather than the window. Its README calls it true modularity in styling responsive components. The package offers a useContainerQuery hook that takes a query and an optional initial size, and a ContainerQuery component that takes the same query and an initialSize with width and height. The hook can measure a native DOM element, such as a div or span, used as the container. If the container is a React component, the README explains that the component must forward its ref to the DOM element it renders, using React.forwardRef, because a React component itself cannot be measured. The README includes a disclaimer that the code is provided under an open source license by contributors acting in a personal capacity. Installation is covered by a package command shown in the README, and the API section documents both the hook and the component.…
Highlights
- useContainerQuery hook for container-based queries
- ContainerQuery component with an initial size
- Works with native DOM containers
- Forwarded refs for React component containers
- Provided under an open source license
Ratings & Reviews
No ratings yet
Be the first to rate react-container-query.
People also visit
react-resize-aware
A React hook that makes it possible to listen to element resize events

responsive-patterns
Responsive design with Container Queries, fluid typography, cqi/cqb units

react-on-screen
A wrapper component to track if your react component is visible on screen
react-container-query FAQ
What is React Container Query?
A React library that makes components respond to the size of their container, not the window.
How do I use the hook?
Call useContainerQuery with a query and an optional initial size. The README shows examples for a DOM element and for a React component container.
What if my container is a React component?
The component must forward its ref to the DOM element it renders, using React.forwardRef, so the size can be measured.
Is it open source?
The README says the code is provided under an open source license.
What are the best react-container-query alternatives?
Popular alternatives to react-container-query include react-height, react-resizable-box and react-resize-aware. See all react-container-query alternatives


















