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