MCPcopy Create free account
hub / github.com/TanStack/query / replaceData

Function replaceData

packages/query-core/src/utils.ts:542–565  ·  view source on GitHub ↗
(prevData: TData | undefined, data: TData, options: TOptions)

Source from the content-addressed store, hash-verified

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

Callers 3

createResultMethod · 0.90
setDataMethod · 0.90
utils.test-d.tsxFile · 0.90

Calls 1

replaceEqualDeepFunction · 0.85

Tested by

no test coverage detected