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

Method setOptions

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

Source from the content-addressed store, hash-verified

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

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