diff --git a/src/index.ts b/src/index.ts index 195188f..0e257fa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,14 @@ +import { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } from 'react' import { useSyncExternalStore } from 'use-sync-external-store/shim'; +declare module 'react' { + var __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: { + ReactCurrentOwner: { + current: null | unknown; + }; + } +} + type VoidFn = () => void; type AnyFn = (...args: unknown[]) => unknown; @@ -109,9 +118,9 @@ const resso = >(obj: Obj): Store => { return obj[key]; } - try { + if (__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner.current !== null) { return state[key].useSnapshot(); - } catch (err) { + } else { return obj[key]; } }