MCPcopy Create free account
hub / github.com/SvelteStack/svelte-query / setData

Method setData

src/queryCore/core/query.ts:231–256  ·  view source on GitHub ↗
(
    updater: Updater<TData | undefined, TData>,
    options?: SetDataOptions
  )

Source from the content-addressed store, hash-verified

229 }
230
231 setData(
232 updater: Updater<TData | undefined, TData>,
233 options?: SetDataOptions
234 ): TData {
235 const prevData = this.state.data
236
237 // Get the new data
238 let data = functionalUpdate(updater, prevData)
239
240 // Use prev data if an isDataEqual function is defined and returns `true`
241 if (this.options.isDataEqual?.(prevData, data)) {
242 data = prevData as TData
243 } else if (this.options.structuralSharing !== false) {
244 // Structurally share data between prev and new data if needed
245 data = replaceEqualDeep(prevData, data)
246 }
247
248 // Set data and mark it as cached
249 this.dispatch({
250 data,
251 type: 'success',
252 dataUpdatedAt: options?.updatedAt,
253 })
254
255 return data
256 }
257
258 setState(
259 state: QueryState<TData, TError>,

Callers 2

fetchMethod · 0.95
setQueryDataMethod · 0.80

Calls 3

dispatchMethod · 0.95
functionalUpdateFunction · 0.90
replaceEqualDeepFunction · 0.90

Tested by

no test coverage detected