Skip to content

Commit

Permalink
useMediaQuery: make it safe for SSR environments without window (#27542)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr authored Dec 8, 2020
1 parent 04b34c6 commit c66baaf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/compose/src/hooks/use-media-query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import { useState, useEffect } from '@wordpress/element';
*/
export default function useMediaQuery( query ) {
const [ match, setMatch ] = useState(
query && window.matchMedia( query ).matches
() =>
!! (
query &&
typeof window !== 'undefined' &&
window.matchMedia( query ).matches
)
);

useEffect( () => {
Expand Down

0 comments on commit c66baaf

Please sign in to comment.