{"version":3,"sources":["../../src/use-signal-state/index.ts"],"sourcesContent":["import { useLatest } from '../use-latest'\nimport { useSafeState } from '../use-safe-state'\nimport { useStableFn } from '../use-stable-fn'\n\nimport type { ReactSetState, UseSafeStateOptions } from '../use-safe-state'\nimport type { Gettable } from '../utils/basic'\n\nexport interface UseSignalStateOptions extends UseSafeStateOptions {}\n\nexport type UseSignalStateReturns<T> = readonly [() => T, ReactSetState<T>]\n\n/**\n * A React Hook similar to `createSignal` from [Solid](https://www.solidjs.com), which allows reading the state value via the `state()` method, **avoiding closure issues**.\n */\nexport function useSignalState<T>(state: Gettable<T>, options: UseSignalStateOptions = {}): UseSignalStateReturns<T> {\n  const [_state, setState] = useSafeState(state, options)\n  const stateRef = useLatest(_state)\n  const stateGetter = useStableFn(() => stateRef.current)\n  return [stateGetter, setState] as const\n}\n"],"names":["useSignalState","state","options","useSafeState","_state","setState","stateRef","useLatest","stateGetter","useStableFn","current"],"mappings":";;;;+BAcgBA;;;eAAAA;;;yBAdU;4BACG;2BACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYrB,SAASA,eAAkBC,KAAkB;QAAEC,UAAAA,iEAAiC,CAAC;IACtF,IAA2BC,iCAAAA,IAAAA,0BAAY,EAACF,OAAOC,cAAxCE,SAAoBD,kBAAZE,WAAYF;IAC3B,IAAMG,WAAWC,IAAAA,oBAAS,EAACH;IAC3B,IAAMI,cAAcC,IAAAA,wBAAW,EAAC;eAAMH,SAASI,OAAO;;IACtD,OAAO;QAACF;QAAaH;KAAS;AAChC"}