From 7ac380a93f3f7c6f60f1078d383c2ba2effec628 Mon Sep 17 00:00:00 2001 From: Mikhail Tsipotan Date: Mon, 27 Nov 2023 06:01:28 +0300 Subject: [PATCH] fix: check for undefined script in getState --- src/components/state.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/state.tsx b/src/components/state.tsx index 36868c6..dc0e641 100644 --- a/src/components/state.tsx +++ b/src/components/state.tsx @@ -78,9 +78,13 @@ export const getState = >( name = STATE_NAME ): T => { const script = document.getElementById(`__${name.toUpperCase()}__`)! - const state = parse(script.textContent!) - script.remove() + let state - return state + if (script) { + state = parse(script.textContent!) + script.remove() + } + + return state as T }