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

Method setOptions

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

* Replaces the query's options and applies their `gcTime`. If the query has no data yet, it gets * the `initialData` from the new options, if any. * @internal * @param options - The new query options, merged on top of the query's default options.

(
    options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,
  )

Source from the content-addressed store, hash-verified

351 * @param options - The new query options, merged on top of the query's default options.
352 */
353 setOptions(
354 options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,
355 ): void {
356 this.options = { ...this.#defaultOptions, ...options }
357
358 if (options?._type) {
359 this.#queryType = options._type
360 }
361
362 this.updateGcTime(this.options.gcTime)
363
364 // oxlint-disable-next-line typescript/no-unnecessary-condition -- the constructor calls 'setOptions' before it assigns 'state'
365 if (this.state && this.state.data === undefined) {
366 const defaultState = getDefaultState(this.options)
367 if (defaultState.data !== undefined) {
368 this.setState(
369 successState(defaultState.data, defaultState.dataUpdatedAt),
370 )
371 this.#initialState = defaultState
372 }
373 }
374 }
375
376 protected override optionalRemove() {
377 if (!this.observers.length && this.state.fetchStatus === 'idle') {

Callers 15

constructorMethod · 0.95
fetchMethod · 0.95
QueryControllerClass · 0.45
applyOptionsMethod · 0.45
applyOptionsMethod · 0.45
refreshOptionsMethod · 0.45
updaterFunction · 0.45
runFunction · 0.45
Devtools.test.tsxFile · 0.45
useBaseQueryFunction · 0.45
useMutationFunction · 0.45

Calls 3

setStateMethod · 0.95
successStateFunction · 0.85
getDefaultStateFunction · 0.70

Tested by

no test coverage detected