score:0

Accepted answer
const mediaQuery = '(max-width: 960px)';
const mediaQueryList = window.matchMedia(mediaQuery);


const MyComponent = () => 
   const [match, updateMatch] = useState(false)
   useEffect(() => {
      const handleChange = (event) => {
          updateMatch(event.matches)
      } 
      mediaQueryList.addEventListener('change', handleChange)
      return () => {
         // This is called the cleanup phase aka beforeUnmount
         mediaQueryList.removeEventListener('change', handleChange)   
      }
   }, []) // Only do this once, aka hook-ish way of saying didMount
   
   const desktopNavActivated = !match

   // ...
   // Further process your match result and return JSX or whatever
}

Related Query

More Query from same tag