{"version":3,"sources":["../../src/useOnValueChange/index.ts"],"names":["useEffect","onValueChange_default","state"],"mappings":";;;;;AAIA,IAAM,gBAAA,GAuBF,CAAC,KAAA,EAAwB,EAAgC,KAAA;AAC3D,EAAA,MAAM,QAAQ,QAAY,IAAA,KAAA;AAE1B,EAAAA,eAAA;AAAA,IACE,MACEC,uCAAc,CAAA,KAAA,EAAc,MAAM;AAChC,MAAG,EAAA,CAAA,KAAA,GAAQ,KAAM,CAAA,GAAA,CAAI,CAACC,MAAAA,KAAUA,MAAM,CAAA,GAAA,EAAK,CAAA,GAAI,KAAM,CAAA,GAAA,EAAK,CAAA;AAAA,KAC3D,CAAA;AAAA,IACH,KAAA,GAAQ,KAAQ,GAAA,CAAC,KAAK;AAAA,GACxB;AACF,CAAA;AAEA,IAAO,wBAAQ,GAAA","file":"chunk-MPKCF5VN.cjs","sourcesContent":["import { useEffect } from 'react';\nimport type { AsyncState, StateBase as State } from '../types';\nimport onValueChange from '../onValueChange';\n\nconst useOnValueChange: {\n  /**\n   * A hook that triggers a callback function when the value of the provided {@link state} changes.\n   * Useful for performing side effects whenever a single state value updates.\n   */\n  <T>(state: AsyncState<T>, cb: (value: T | undefined) => void): void;\n  /**\n   * A hook that triggers a callback function when the value of the provided {@link state} changes.\n   * Useful for performing side effects whenever a single state value updates.\n   */\n  <T>(state: State<T>, cb: (value: T) => void): void;\n  /**\n   * A hook that triggers a callback function when the values of multiple {@link states} change.\n   * Useful for performing side effects whenever any of the provided state values update.\n   */\n  <const S extends State[]>(\n    states: S,\n    cb: (values: {\n      [index in keyof S]: S[index] extends State<infer K>\n        ? K | (S[index] extends AsyncState ? undefined : never)\n        : never;\n    }) => void\n  ): void;\n} = (state: State | State[], cb: (values: any[]) => void) => {\n  const isArr = 'length' in state;\n\n  useEffect(\n    () =>\n      onValueChange(state as any, () => {\n        cb(isArr ? state.map((state) => state.get()) : state.get());\n      }),\n    isArr ? state : [state]\n  );\n};\n\nexport default useOnValueChange;\n"]}