(prevData: TData | undefined, data: TData, options: TOptions)
| 367 | } |
| 368 | |
| 369 | export function replaceData< |
| 370 | TData, |
| 371 | TOptions extends QueryOptions<any, any, any, any>, |
| 372 | >(prevData: TData | undefined, data: TData, options: TOptions): TData { |
| 373 | if (typeof options.structuralSharing === 'function') { |
| 374 | return options.structuralSharing(prevData, data) as TData |
| 375 | } else if (options.structuralSharing !== false) { |
| 376 | if (process.env.NODE_ENV !== 'production') { |
| 377 | try { |
| 378 | return replaceEqualDeep(prevData, data) |
| 379 | } catch (error) { |
| 380 | console.error( |
| 381 | `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}`, |
| 382 | ) |
| 383 | |
| 384 | // Prevent the replaceEqualDeep from being called again down below. |
| 385 | throw error |
| 386 | } |
| 387 | } |
| 388 | // Structurally share data between prev and new data if needed |
| 389 | return replaceEqualDeep(prevData, data) |
| 390 | } |
| 391 | return data |
| 392 | } |
| 393 | |
| 394 | export function keepPreviousData<T>( |
| 395 | previousData: T | undefined, |
no test coverage detected
searching dependent graphs…