0.2.0 • Published 5 years ago
use-container-query v0.2.0
use-container-query
React hook for element-based media queries.
Install
yarn add use-container-queryUsage
import useContainerQuery from 'use-container-query';
function LandscapeOnly() {
const ref = useRef(null);
const isLandscape = useContainerQuery(ref, {
type: 'orientation',
value: 'landscape',
});
return (
<div ref={ref}>
{ isLandscape
? 'This element is on landscape orientation'
: 'This element is on portrait orientation'
}
</div>
);
}Supported queries
aspect-ratiomax-aspect-ratiomin-aspect-ratiowidthmax-widthmin-widthheightmax-heightmin-heightorientationvaluemust be either'portrait'or'landscape'
License
MIT © lxsmnsyc