{"version":3,"file":"use-shallow-effect.cjs","names":["shallowEqual"],"sources":["../../src/use-shallow-effect/use-shallow-effect.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { shallowEqual } from '../utils/shallow-equal/shallow-equal';\n\nfunction shallowCompare(prevValue?: React.DependencyList | null, currValue?: React.DependencyList) {\n  if (!prevValue || !currValue) {\n    return false;\n  }\n\n  if (prevValue === currValue) {\n    return true;\n  }\n\n  if (prevValue.length !== currValue.length) {\n    return false;\n  }\n\n  for (let i = 0; i < prevValue.length; i += 1) {\n    if (!shallowEqual(prevValue[i], currValue[i])) {\n      return false;\n    }\n  }\n\n  return true;\n}\n\nfunction useShallowCompare(dependencies?: React.DependencyList) {\n  const ref = useRef<React.DependencyList | null | undefined>([]);\n  const updateRef = useRef<number>(0);\n\n  if (!shallowCompare(ref.current, dependencies)) {\n    ref.current = dependencies;\n    updateRef.current += 1;\n  }\n\n  return [updateRef.current];\n}\n\nexport function useShallowEffect(cb: () => void, dependencies?: React.DependencyList): void {\n  useEffect(cb, useShallowCompare(dependencies));\n}\n"],"mappings":";;;;AAGA,SAAS,eAAe,WAAyC,WAAkC;CACjG,IAAI,CAAC,aAAa,CAAC,WACjB,OAAO;CAGT,IAAI,cAAc,WAChB,OAAO;CAGT,IAAI,UAAU,WAAW,UAAU,QACjC,OAAO;CAGT,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK,GACzC,IAAI,CAACA,sBAAAA,aAAa,UAAU,IAAI,UAAU,EAAE,GAC1C,OAAO;CAIX,OAAO;AACT;AAEA,SAAS,kBAAkB,cAAqC;CAC9D,MAAM,OAAA,GAAA,MAAA,QAAsD,CAAC,CAAC;CAC9D,MAAM,aAAA,GAAA,MAAA,QAA2B,CAAC;CAElC,IAAI,CAAC,eAAe,IAAI,SAAS,YAAY,GAAG;EAC9C,IAAI,UAAU;EACd,UAAU,WAAW;CACvB;CAEA,OAAO,CAAC,UAAU,OAAO;AAC3B;AAEA,SAAgB,iBAAiB,IAAgB,cAA2C;CAC1F,CAAA,GAAA,MAAA,WAAU,IAAI,kBAAkB,YAAY,CAAC;AAC/C"}