{"version":3,"file":"useStableValue.cjs","names":["_react","require","_isDeepEqual","useStableValue","value","stableValueRef","useRef","isDeepEqual","firstValue","current","secondValue","exports"],"sources":["../../../../src/charts/utils/useStableValue.ts"],"sourcesContent":["/*!\n * Copyright (c) 2026-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { useRef } from \"react\";\n\nimport { isDeepEqual } from \"../../isDeepEqual.js\";\n\n/**\n * Returns the same object for as long as the contents of `value` stay the same. The hook returns the new object after a content change.\n *\n * A chart needs this hook because the chart library rebuilds and redraws the whole chart when the identity of its React children changes. A caller that builds a `series` array inside its own render supplies a new array on each render, and every memo below that point then misses. A comparison of the contents costs one walk over the points, which is far less than one redraw of the chart.\n *\n * The comparison treats a function by its identity, because two functions with the same body can still behave differently. Therefore a caller that supplies a new function on each render, such as an inline formatter, gets a new object from this hook on each render.\n */\nexport const useStableValue = <ValueType>(value: ValueType): ValueType => {\n  // This hook writes to the ref during the render. The write is safe here because the new value comes only from `value`, so a second render with the same input reaches the same result.\n  const stableValueRef = useRef(value);\n\n  if (\n    !isDeepEqual({ firstValue: stableValueRef.current, secondValue: value })\n  ) {\n    stableValueRef.current = value;\n  }\n\n  return stableValueRef.current;\n};\n"],"mappings":";;;;;;AAYA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAaO,MAAME,cAAc,GAAeC,KAAgB,IAAgB;EAExE,MAAMC,cAAc,GAAG,IAAAC,aAAM,EAACF,KAAK,CAAC;EAEpC,IACE,CAAC,IAAAG,wBAAW,EAAC;IAAEC,UAAU,EAAEH,cAAc,CAACI,OAAO;IAAEC,WAAW,EAAEN;EAAM,CAAC,CAAC,EACxE;IACAC,cAAc,CAACI,OAAO,GAAGL,KAAK;EAChC;EAEA,OAAOC,cAAc,CAACI,OAAO;AAC/B,CAAC;AAACE,OAAA,CAAAR,cAAA,GAAAA,cAAA","ignoreList":[]}