Implement a useMediaQuery hook that subscribes to 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>;}
query: string: The media query to match. It must be a valid CSS media query stringThe hook returns a boolean value that indicates whether the media query matches.
window.matchMedia(query).matches.change event and update state when it changes.query changes, unsubscribe from the old MediaQueryList and subscribe to the new one.resize listener.