{"version":3,"sources":["../../src/use-last-updated/index.ts"],"sourcesContent":["import { useSafeState } from '../use-safe-state'\nimport { useUpdateDeepCompareEffect } from '../use-update-deep-compare-effect'\nimport { useUpdateEffect } from '../use-update-effect'\nimport { timestamp } from '../utils/basic'\n\nexport interface UseLastChangedOptions {\n  /**\n   * The initial value of the last updated timestamp.\n   *\n   * @defaultValue null\n   */\n  initialValue?: number | null\n  /**\n   * If `true`, deep compares the source object.\n   *\n   * @defaultValue false\n   */\n  deep?: boolean\n}\n\n/**\n * A React Hook that record the last updated time of a state.\n */\nexport function useLastUpdated<T = unknown>(source: T, options?: UseLastChangedOptions): number | null {\n  const { initialValue = null, deep = false } = options ?? {}\n  const [updatedAt, setUpdatedAt] = useSafeState<number | null>(initialValue)\n\n  useUpdateEffect(() => void setUpdatedAt(timestamp()), deep ? [] : [source])\n  useUpdateDeepCompareEffect(() => void setUpdatedAt(timestamp()), deep ? [source] : [])\n\n  return updatedAt\n}\n"],"names":["useLastUpdated","source","options","initialValue","deep","useSafeState","updatedAt","setUpdatedAt","useUpdateEffect","timestamp","useUpdateDeepCompareEffect"],"mappings":";;;;+BAuBgBA;;;eAAAA;;;4BAvBa;0CACc;+BACX;qBACN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBnB,SAASA,eAA4BC,MAAS,EAAEC,OAA+B;IACpF,IAA8CA,OAAAA,oBAAAA,qBAAAA,UAAW,CAAC,uBAAZA,KAAtCC,cAAAA,8CAAe,sCAAuBD,KAAjBE,MAAAA,8BAAO;IACpC,IAAkCC,iCAAAA,IAAAA,0BAAY,EAAgBF,mBAAvDG,YAA2BD,kBAAhBE,eAAgBF;IAElCG,IAAAA,gCAAe,EAAC;eAAM,KAAKD,aAAaE,IAAAA,gBAAS;OAAKL,OAAO,EAAE,GAAG;QAACH;KAAO;IAC1ES,IAAAA,sDAA0B,EAAC;eAAM,KAAKH,aAAaE,IAAAA,gBAAS;OAAKL,OAAO;QAACH;KAAO,GAAG,EAAE;IAErF,OAAOK;AACT"}