From 6aebe3bf1affb52518bf1223abddd571436b2068 Mon Sep 17 00:00:00 2001 From: Francesco Giordano Date: Thu, 15 Jun 2023 16:35:42 +0200 Subject: [PATCH] Pass displayed data as second parameter of functional optimistic data --- _internal/src/types.ts | 4 +++- _internal/src/utils/mutate.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/_internal/src/types.ts b/_internal/src/types.ts index 3b399b392..5db1b6679 100644 --- a/_internal/src/types.ts +++ b/_internal/src/types.ts @@ -317,7 +317,9 @@ export type MutatorOptions = { populateCache?: | boolean | ((result: any, currentData: Data | undefined) => Data) - optimisticData?: Data | ((currentData?: Data) => Data) + optimisticData?: + | Data + | ((currentData: Data | undefined, displayedData: Data | undefined) => Data) rollbackOnError?: boolean | ((error: unknown) => boolean) throwOnError?: boolean } diff --git a/_internal/src/utils/mutate.ts b/_internal/src/utils/mutate.ts index 36331933d..2e86ff298 100644 --- a/_internal/src/utils/mutate.ts +++ b/_internal/src/utils/mutate.ts @@ -139,7 +139,7 @@ export async function internalMutate( // Do optimistic data update. if (hasOptimisticData) { optimisticData = isFunction(optimisticData) - ? optimisticData(committedData) + ? optimisticData(committedData, displayedData) : optimisticData // When we set optimistic data, backup the current committedData data in `_c`.