{"version":3,"sources":["../../src/useValue/index.ts"],"names":["useSyncExternalStore","_subscribeWithLoad","_onValueChange","_valueToggler","alwaysNoop_default","noop"],"mappings":";;;;;;;;;;AAUA,IAAM,QAAA,GAAY,CAAC,KAAiC,KAAA;AAClD,EAAA,IAAI,KAAO,EAAA;AACT,IAAAA,0BAAA;AAAA,MACE,KAAA,CAAMC,KAAsB,KAAMC,CAAAA,CAAAA;AAAA,MAClC,MAAM,KAAMC,CAAAA;AAAA,KACd;AAEA,IAAA,OAAO,MAAM,GAAI,EAAA;AAAA;AAGnB,EAAAH,0BAAA,CAAqBI,sCAAYC,qBAAI,CAAA;AACvC,CAAA;AAaA,IAAO,gBAAQ,GAAA","file":"chunk-JOROVUKO.cjs","sourcesContent":["import { useSyncExternalStore } from 'react';\nimport type {\n  AnyAsyncState,\n  AsyncState,\n  Falsy,\n  StateBase as State,\n} from '../types';\nimport noop from 'lodash.noop';\nimport alwaysNoop from '../utils/alwaysNoop';\n\nconst useValue = ((state: AnyAsyncState | Falsy) => {\n  if (state) {\n    useSyncExternalStore(\n      state._subscribeWithLoad || state._onValueChange,\n      () => state._valueToggler\n    );\n\n    return state.get();\n  }\n\n  useSyncExternalStore(alwaysNoop, noop);\n}) as {\n  /**\n   * A hook to retrieve the current value from the provided {@link state}.\n   * It ensures that the component re-renders whenever the {@link state} value changes.\n   * If the provided {@link state} is falsy, the hook returns `undefined` and performs no operations.\n   */\n  <S extends State | Falsy>(\n    state: S\n  ): S extends State<infer K>\n    ? K | (S extends AsyncState ? undefined : never)\n    : never;\n};\n\nexport default useValue;\n"]}