From 4398df13d50499c317c02e912380a02dd7937fe9 Mon Sep 17 00:00:00 2001 From: Oriol Raventos Date: Thu, 3 Oct 2024 09:31:21 +0200 Subject: [PATCH] refactor(plugin-flow-builder): applay early return --- .../src/webview/use-webview-contents.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts b/packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts index 9d87fad75..78f08be03 100644 --- a/packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts +++ b/packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts @@ -32,9 +32,12 @@ export function useWebviewContents({ const [error, setError] = useState(false) const updateCurrentLocale = (textContents?: WebviewTextContent[]) => { + if (!textContents || textContents.length === 0) { + console.log('There is no text contents to check the locale') + return + } + if ( - textContents && - textContents?.length > 0 && textContents[0].content.text.some(text => text.locale === currentLocale) ) { setCurrentLocale(currentLocale) @@ -42,7 +45,7 @@ export function useWebviewContents({ } const language = currentLocale.split('-')[0] - if (textContents?.[0].content.text.some(text => text.locale === language)) { + if (textContents[0].content.text.some(text => text.locale === language)) { setCurrentLocale(language) return }