@tanstack/react-query 4.1.3 → 4.2.3

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.
@@ -45,9 +45,10 @@ export interface QueryOptions<TQueryFnData = unknown, TError = unknown, TData =
45
45
  behavior?: QueryBehavior<TQueryFnData, TError, TData>;
46
46
  /**
47
47
  * Set this to `false` to disable structural sharing between query results.
48
+ * Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom structural sharing logic.
48
49
  * Defaults to `true`.
49
50
  */
50
- structuralSharing?: boolean;
51
+ structuralSharing?: boolean | ((oldData: TData | undefined, newData: TData) => TData);
51
52
  /**
52
53
  * This function can be set to automatically get the previous cursor for infinite queries.
53
54
  * The result will also be used to determine the value of `hasPreviousPage`.
@@ -377,6 +377,8 @@
377
377
  // Use prev data if an isDataEqual function is defined and returns `true`
378
378
  if (options.isDataEqual != null && options.isDataEqual(prevData, data)) {
379
379
  return prevData;
380
+ } else if (typeof options.structuralSharing === 'function') {
381
+ return options.structuralSharing(prevData, data);
380
382
  } else if (options.structuralSharing !== false) {
381
383
  // Structurally share data between prev and new data if needed
382
384
  return replaceEqualDeep(prevData, data);