From d67a7da0aff36c4b6f44907bbd91545022d5b8a7 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Mon, 7 Dec 2020 11:46:14 +0100 Subject: [PATCH] useMediaQuery: make it safe for SSR environments without window --- packages/compose/src/hooks/use-media-query/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/compose/src/hooks/use-media-query/index.js b/packages/compose/src/hooks/use-media-query/index.js index 63168c218a6e5f..8c0f0844d6b1c4 100644 --- a/packages/compose/src/hooks/use-media-query/index.js +++ b/packages/compose/src/hooks/use-media-query/index.js @@ -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( () => {