useMediaQuery

Author
AI Engineer
Languages

Implement a useMediaQuery hook that subscribes and responds to media query changes (e.g. screen size, resolution, orientation, etc.).

export default function Component() {
const isSmallDevice = useMediaQuery('only screen and (max-width: 768px)');
return <div>{isSmallDevice && <a href="#">Menu</a>}</div>;
}

Hint: The window.matchMedia API would be helpful.

Arguments

Returns

The hook returns a boolean value that indicates whether the media query is a match.