Skip to content

Commit

Permalink
Pass displayed data as second parameter of functional optimistic data
Browse files Browse the repository at this point in the history
  • Loading branch information
francescogior committed Jun 17, 2023
1 parent 55bfc88 commit 6aebe3b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion _internal/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ export type MutatorOptions<Data = any> = {
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
}
Expand Down
2 changes: 1 addition & 1 deletion _internal/src/utils/mutate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export async function internalMutate<Data>(
// 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`.
Expand Down

0 comments on commit 6aebe3b

Please sign in to comment.