Skip to content

Commit

Permalink
Merge pull request #12 from asyncink/get-state-undefined-script
Browse files Browse the repository at this point in the history
fix: check for undefined script in getState
  • Loading branch information
andrepolischuk authored Nov 27, 2023
2 parents 6edde18 + 7ac380a commit d0478d4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ export const getState = <T extends Record<string, any>>(
name = STATE_NAME
): T => {
const script = document.getElementById(`__${name.toUpperCase()}__`)!
const state = parse<T>(script.textContent!)

script.remove()
let state

return state
if (script) {
state = parse<T>(script.textContent!)
script.remove()
}

return state as T
}

0 comments on commit d0478d4

Please sign in to comment.