From 54cfbaf3d7e3b7d417b180075811bf04c165df2d Mon Sep 17 00:00:00 2001 From: Colin Murphy Date: Fri, 20 Dec 2024 17:45:09 +0000 Subject: [PATCH] Fixed logic --- .../src/components/WordPressBlocksProvider.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/blocks/src/components/WordPressBlocksProvider.tsx b/packages/blocks/src/components/WordPressBlocksProvider.tsx index 90e96d8a1..d1d5425e5 100644 --- a/packages/blocks/src/components/WordPressBlocksProvider.tsx +++ b/packages/blocks/src/components/WordPressBlocksProvider.tsx @@ -68,23 +68,20 @@ export function WordPressBlocksProvider(props: { * const theme = useBlocksTheme(); * ``` */ -export function useBlocksTheme(): BlocksTheme | null { +export function useBlocksTheme(): BlocksTheme { // If it's an empty object, the provider hasn't been initialized.± - if (typeof WordPressBlocksContext === 'undefined') { + if (typeof WordPressBlocksContext === 'undefined' || typeof WordPressBlocksContext === 'undefined') { throw new Error( 'useBlocksTheme hook was called outside of context, make sure your app is wrapped with WordPressBlocksProvider', ); } - // Theme is optional - if (typeof WordPressBlocksContext === 'undefined' || WordPressBlocksContext === null) { - return null; - } - const themeContext = React.useContext(WordPressThemeContext); - if (typeof themeContext === 'undefined' || themeContext === null) { - return null; + if (typeof themeContext === 'undefined') { + throw new Error( + 'useBlocksTheme hook was called outside of context, make sure your app is wrapped with WordPressBlocksProvider', + ); } return themeContext;