@trackunit/react-components 1.17.10 → 1.17.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -3335,27 +3335,33 @@ const useDebounce = (value, { onBounce, delay = 500 } = {}) => {
3335
3335
  const UNINITIALIZED = Symbol("UNINITIALIZED");
3336
3336
  /**
3337
3337
  * Hook to watch for changes in a value and react to them.
3338
- * Uses deep equality comparison via es-toolkit's isEqual.
3338
+ * Uses deep equality comparison via es-toolkit's isEqual by default.
3339
3339
  *
3340
3340
  * @param props - The hook properties
3341
3341
  * @param props.value - The value to watch for changes
3342
3342
  * @param props.onChange - Function to call when the value changes
3343
3343
  * @param props.immediate - Whether to run the callback immediately on mount (default: false)
3344
3344
  * @param props.skip - Whether to skip watching for changes (default: false)
3345
+ * @param props.isEqual - Custom equality function to override the default deep comparison.
3346
+ * Useful when the watched value contains fields (e.g. function references) that are
3347
+ * new on every render but are not meaningful for change detection. (default: es-toolkit's isEqual)
3345
3348
  */
3346
- const useWatch = ({ value, onChange, immediate = false, skip = false }) => {
3349
+ const useWatch = ({ value, onChange, immediate = false, skip = false, isEqual = esToolkit.isEqual, }) => {
3347
3350
  const prevValue = react.useRef(UNINITIALIZED);
3348
3351
  const onChangeRef = react.useRef(onChange);
3349
- // Update the ref whenever onChange changes
3352
+ const isEqualRef = react.useRef(isEqual);
3350
3353
  react.useEffect(() => {
3351
3354
  onChangeRef.current = onChange;
3352
3355
  }, [onChange]);
3356
+ react.useEffect(() => {
3357
+ isEqualRef.current = isEqual;
3358
+ }, [isEqual]);
3353
3359
  react.useEffect(() => {
3354
3360
  if (skip) {
3355
3361
  return;
3356
3362
  }
3357
3363
  const prev = prevValue.current;
3358
- const hasChanged = prev === UNINITIALIZED ? false : !esToolkit.isEqual(value, prev);
3364
+ const hasChanged = prev === UNINITIALIZED ? false : !isEqualRef.current(value, prev);
3359
3365
  if (immediate && prev === UNINITIALIZED) {
3360
3366
  onChangeRef.current(value, null);
3361
3367
  }
package/index.esm.js CHANGED
@@ -3333,27 +3333,33 @@ const useDebounce = (value, { onBounce, delay = 500 } = {}) => {
3333
3333
  const UNINITIALIZED = Symbol("UNINITIALIZED");
3334
3334
  /**
3335
3335
  * Hook to watch for changes in a value and react to them.
3336
- * Uses deep equality comparison via es-toolkit's isEqual.
3336
+ * Uses deep equality comparison via es-toolkit's isEqual by default.
3337
3337
  *
3338
3338
  * @param props - The hook properties
3339
3339
  * @param props.value - The value to watch for changes
3340
3340
  * @param props.onChange - Function to call when the value changes
3341
3341
  * @param props.immediate - Whether to run the callback immediately on mount (default: false)
3342
3342
  * @param props.skip - Whether to skip watching for changes (default: false)
3343
+ * @param props.isEqual - Custom equality function to override the default deep comparison.
3344
+ * Useful when the watched value contains fields (e.g. function references) that are
3345
+ * new on every render but are not meaningful for change detection. (default: es-toolkit's isEqual)
3343
3346
  */
3344
- const useWatch = ({ value, onChange, immediate = false, skip = false }) => {
3347
+ const useWatch = ({ value, onChange, immediate = false, skip = false, isEqual: isEqual$1 = isEqual, }) => {
3345
3348
  const prevValue = useRef(UNINITIALIZED);
3346
3349
  const onChangeRef = useRef(onChange);
3347
- // Update the ref whenever onChange changes
3350
+ const isEqualRef = useRef(isEqual$1);
3348
3351
  useEffect(() => {
3349
3352
  onChangeRef.current = onChange;
3350
3353
  }, [onChange]);
3354
+ useEffect(() => {
3355
+ isEqualRef.current = isEqual$1;
3356
+ }, [isEqual$1]);
3351
3357
  useEffect(() => {
3352
3358
  if (skip) {
3353
3359
  return;
3354
3360
  }
3355
3361
  const prev = prevValue.current;
3356
- const hasChanged = prev === UNINITIALIZED ? false : !isEqual(value, prev);
3362
+ const hasChanged = prev === UNINITIALIZED ? false : !isEqualRef.current(value, prev);
3357
3363
  if (immediate && prev === UNINITIALIZED) {
3358
3364
  onChangeRef.current(value, null);
3359
3365
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "1.17.10",
3
+ "version": "1.17.11",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -14,10 +14,10 @@
14
14
  "@floating-ui/react": "^0.26.25",
15
15
  "string-ts": "^2.0.0",
16
16
  "tailwind-merge": "^2.0.0",
17
- "@trackunit/ui-design-tokens": "1.11.39",
18
- "@trackunit/css-class-variance-utilities": "1.11.39",
19
- "@trackunit/shared-utils": "1.13.39",
20
- "@trackunit/ui-icons": "1.11.38",
17
+ "@trackunit/ui-design-tokens": "1.11.40",
18
+ "@trackunit/css-class-variance-utilities": "1.11.40",
19
+ "@trackunit/shared-utils": "1.13.40",
20
+ "@trackunit/ui-icons": "1.11.39",
21
21
  "@tanstack/react-router": "1.114.29",
22
22
  "es-toolkit": "^1.39.10",
23
23
  "@tanstack/react-virtual": "3.13.12",
@@ -1,20 +1,24 @@
1
- interface UseWatchOptions {
1
+ interface UseWatchOptions<TValue> {
2
2
  immediate?: boolean;
3
3
  skip?: boolean;
4
+ isEqual?: (a: TValue, b: TValue) => boolean;
4
5
  }
5
- interface UseWatchProps<TValue> extends UseWatchOptions {
6
+ interface UseWatchProps<TValue> extends UseWatchOptions<TValue> {
6
7
  value: TValue;
7
8
  onChange: (value: TValue, prevValue: TValue | null) => void;
8
9
  }
9
10
  /**
10
11
  * Hook to watch for changes in a value and react to them.
11
- * Uses deep equality comparison via es-toolkit's isEqual.
12
+ * Uses deep equality comparison via es-toolkit's isEqual by default.
12
13
  *
13
14
  * @param props - The hook properties
14
15
  * @param props.value - The value to watch for changes
15
16
  * @param props.onChange - Function to call when the value changes
16
17
  * @param props.immediate - Whether to run the callback immediately on mount (default: false)
17
18
  * @param props.skip - Whether to skip watching for changes (default: false)
19
+ * @param props.isEqual - Custom equality function to override the default deep comparison.
20
+ * Useful when the watched value contains fields (e.g. function references) that are
21
+ * new on every render but are not meaningful for change detection. (default: es-toolkit's isEqual)
18
22
  */
19
- export declare const useWatch: <TValue>({ value, onChange, immediate, skip }: UseWatchProps<TValue>) => void;
23
+ export declare const useWatch: <TValue>({ value, onChange, immediate, skip, isEqual, }: UseWatchProps<TValue>) => void;
20
24
  export {};