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

Method setOptions

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

Source from the content-addressed store, hash-verified

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

Callers 1

constructorMethod · 0.95

Calls 14

#updateQueryMethod · 0.95
#executeFetchMethod · 0.95
updateResultMethod · 0.95
#updateStaleTimeoutMethod · 0.95
resolveQueryBooleanFunction · 0.90
shallowEqualObjectsFunction · 0.90
resolveStaleTimeFunction · 0.90
shouldFetchOptionallyFunction · 0.85
defaultQueryOptionsMethod · 0.80
getQueryCacheMethod · 0.80

Tested by

no test coverage detected