useMediaMatch
Aboutβ
Signal whether or not a media query is currently matched.
Installationβ
npm install --save rooks
Importing the hookβ
import { useMediaMatch } from "rooks";
Usageβ
function Demo() {
const isNarrowWidth = useMediaMatch("(max-width: 600px)");
return <span>Your screen is {isNarrowWidth ? "narrow" : "wide"}</span>;
}
render(<Demo />);
Argumentsβ
Argument value | Type | Description |
---|---|---|
query | string | The media query to signal on. Example, "print" will signal true when previewing in print mode, and false otherwise |
Returnsβ
Return value | Type | Description |
---|---|---|
isMatch | Boolean | Whether or not the media query is currently matched |
Codesandbox Examplesβ
Basic Usageβ
Join Bhargav's discord serverβ
You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.