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

Method setData

packages/query-core/src/query.ts:390–405  ·  view source on GitHub ↗

* Writes new data to the query and marks it as successfully fetched. * @internal * @param newData - The data to write. Structural sharing with the current data is applied. * @param options - Set `updatedAt` to override the timestamp, and `manual` to mark the write as * manual (e.g. from

(
    newData: TData,
    options?: SetDataOptions & { manual: boolean },
  )

Source from the content-addressed store, hash-verified

388 * @returns The data that was written.
389 */
390 setData(
391 newData: TData,
392 options?: SetDataOptions & { manual: boolean },
393 ): TData {
394 const data = replaceData(this.state.data, newData, this.options)
395
396 // Set data and mark it as cached
397 this.#dispatch({
398 data,
399 type: 'success',
400 dataUpdatedAt: options?.updatedAt,
401 manual: options?.manual,
402 })
403
404 return data
405 }
406
407 /**
408 * Merges the given partial state directly into this query's state, notifying observers. Used

Callers 5

fetchMethod · 0.95
setQueryDataMethod · 0.80
predicateFunction · 0.80
query.test-d.tsxFile · 0.80

Calls 2

#dispatchMethod · 0.95
replaceDataFunction · 0.90

Tested by 1

predicateFunction · 0.64