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

Method setOptions

packages/query-core/src/queryObserver.ts:133–215  ·  view source on GitHub ↗
(
    options: QueryObserverOptions<
      TQueryFnData,
      TError,
      TData,
      TQueryData,
      TQueryKey
    >,
  )

Source from the content-addressed store, hash-verified

131 }
132
133 setOptions(
134 options: QueryObserverOptions<
135 TQueryFnData,
136 TError,
137 TData,
138 TQueryData,
139 TQueryKey
140 >,
141 ): void {
142 const prevOptions = this.options
143 const prevQuery = this.#currentQuery
144
145 this.options = this.#client.defaultQueryOptions(options)
146
147 if (
148 this.options.enabled !== undefined &&
149 typeof this.options.enabled !== 'boolean' &&
150 typeof this.options.enabled !== 'function' &&
151 typeof resolveQueryValue(this.options.enabled, this.#currentQuery) !==
152 'boolean'
153 ) {
154 throw new Error(
155 'Expected enabled to be a boolean or a callback that returns a boolean',
156 )
157 }
158
159 this.#updateQuery()
160 this.#currentQuery.setOptions(this.options)
161
162 if (
163 prevOptions._defaulted &&
164 !shallowEqualObjects(this.options, prevOptions)
165 ) {
166 this.#client.getQueryCache().notify({
167 type: 'observerOptionsUpdated',
168 query: this.#currentQuery,
169 observer: this,
170 })
171 }
172
173 const mounted = this.hasListeners()
174
175 // Fetch if there are subscribers
176 if (
177 mounted &&
178 shouldFetchOptionally(
179 this.#currentQuery,
180 prevQuery,
181 this.options,
182 prevOptions,
183 )
184 ) {
185 this.#executeFetch()
186 }
187
188 // Update result
189 this.updateResult()
190

Callers 1

constructorMethod · 0.95

Calls 13

#updateQueryMethod · 0.95
#executeFetchMethod · 0.95
updateResultMethod · 0.95
#updateStaleTimeoutMethod · 0.95
resolveQueryValueFunction · 0.90
shallowEqualObjectsFunction · 0.90
shouldFetchOptionallyFunction · 0.85
defaultQueryOptionsMethod · 0.80
getQueryCacheMethod · 0.80
hasListenersMethod · 0.80

Tested by

no test coverage detected