(prevData: TData | undefined, data: TData, options: TOptions)
| 458 | } |
| 459 | |
| 460 | export function replaceData< |
| 461 | TData, |
| 462 | TOptions extends QueryOptions<any, any, any, any>, |
| 463 | >(prevData: TData | undefined, data: TData, options: TOptions): TData { |
| 464 | if (typeof options.structuralSharing === 'function') { |
| 465 | return options.structuralSharing(prevData, data) as TData |
| 466 | } else if (options.structuralSharing !== false) { |
| 467 | if (process.env.NODE_ENV !== 'production') { |
| 468 | try { |
| 469 | return replaceEqualDeep(prevData, data) |
| 470 | } catch (error) { |
| 471 | console.error( |
| 472 | `Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${options.queryHash}]: ${error}`, |
| 473 | ) |
| 474 | |
| 475 | // Prevent the replaceEqualDeep from being called again down below. |
| 476 | throw error |
| 477 | } |
| 478 | } |
| 479 | // Structurally share data between prev and new data if needed |
| 480 | return replaceEqualDeep(prevData, data) |
| 481 | } |
| 482 | return data |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * Intended to be passed as a query's `placeholderData` option, for example |
no test coverage detected