(prevData: TData | undefined, data: TData, options: TOptions)
| 544 | * Outside production, it is also logged to the console. |
| 545 | */ |
| 546 | export function replaceData< |
| 547 | TData, |
| 548 | TOptions extends QueryOptions<any, any, any, any>, |
| 549 | >(prevData: TData | undefined, data: TData, options: TOptions): TData { |
| 550 | if (typeof options.structuralSharing === 'function') { |
| 551 | return options.structuralSharing(prevData, data) as TData |
| 552 | } else if (options.structuralSharing !== false) { |
| 553 | if (process.env.NODE_ENV !== 'production') { |
| 554 | try { |
| 555 | return replaceEqualDeep(prevData, data) |
| 556 | } catch (error) { |
| 557 | console.error( |
| 558 | `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}`, |
| 559 | ) |
| 560 | |
| 561 | // Prevent the replaceEqualDeep from being called again down below. |
| 562 | throw error |
| 563 | } |
| 564 | } |
| 565 | // Structurally share data between prev and new data if needed |
| 566 | return replaceEqualDeep(prevData, data) |
| 567 | } |
| 568 | return data |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Intended to be passed as a query's `placeholderData` option, for example |
no test coverage detected