From c66baaf9af3debac9f8418e3abd25255b66ec1ba Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Tue, 8 Dec 2020 13:34:31 +0100 Subject: [PATCH] useMediaQuery: make it safe for SSR environments without window (#27542) --- 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( () => {