(prevData: TData | undefined, data: TData, options: TOptions)
| 391 | } |
| 392 | |
| 393 | export function replaceData< |
| 394 | TData, |
| 395 | TOptions extends QueryOptions<any, any, any, any>, |
| 396 | >(prevData: TData | undefined, data: TData, options: TOptions): TData { |
| 397 | if (typeof options.structuralSharing === 'function') { |
| 398 | return options.structuralSharing(prevData, data) as TData |
| 399 | } else if (options.structuralSharing !== false) { |
| 400 | if (process.env.NODE_ENV !== 'production') { |
| 401 | try { |
| 402 | return replaceEqualDeep(prevData, data) |
| 403 | } catch (error) { |
| 404 | console.error( |
| 405 | `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}`, |
| 406 | ) |
| 407 | |
| 408 | // Prevent the replaceEqualDeep from being called again down below. |
| 409 | throw error |
| 410 | } |
| 411 | } |
| 412 | // Structurally share data between prev and new data if needed |
| 413 | return replaceEqualDeep(prevData, data) |
| 414 | } |
| 415 | return data |
| 416 | } |
| 417 | |
| 418 | export function keepPreviousData<T>( |
| 419 | previousData: T | undefined, |
no test coverage detected