diff --git a/frontend/util/util.ts b/frontend/util/util.ts index 4f06f3f2..6221db21 100644 --- a/frontend/util/util.ts +++ b/frontend/util/util.ts @@ -3,6 +3,7 @@ import base64 from "base64-js"; import clsx from "clsx"; +import * as jotai from "jotai"; function isBlank(str: string): boolean { return str == null || str == ""; @@ -152,6 +153,15 @@ function jotaiLoadableValue(value: Loadable, def: T): T { return def; } +const NullAtom = jotai.atom(null); + +function useAtomValueSafe(atom: jotai.Atom): T { + if (atom == null) { + return jotai.useAtomValue(NullAtom) as T; + } + return jotai.useAtomValue(atom); +} + export { base64ToArray, base64ToString, @@ -163,4 +173,5 @@ export { jsonDeepEqual, makeIconClass, stringToBase64, + useAtomValueSafe, };