* Synchronous way to immediately update a query's cached data. If the updater (or the value * passed) resolves to `undefined`, the cache is left untouched and no query is created; * otherwise, if the query does not exist yet, it will be created. To update multiple queries * at once by parti
(
queryKey: TTaggedQueryKey,
updater: Updater<
NoInfer<TInferredQueryFnData> | undefined,
NoInfer<TInferredQueryFnData> | undefined
>,
options?: SetDataOptions,
)
| 276 | * ``` |
| 277 | */ |
| 278 | setQueryData< |
| 279 | TQueryFnData = unknown, |
| 280 | TTaggedQueryKey extends QueryKey = QueryKey, |
| 281 | TInferredQueryFnData = InferDataFromTag<TQueryFnData, TTaggedQueryKey>, |
| 282 | >( |
| 283 | queryKey: TTaggedQueryKey, |
| 284 | updater: Updater< |
| 285 | NoInfer<TInferredQueryFnData> | undefined, |
| 286 | NoInfer<TInferredQueryFnData> | undefined |
| 287 | >, |
| 288 | options?: SetDataOptions, |
| 289 | ): NoInfer<TInferredQueryFnData> | undefined { |
| 290 | const defaultedOptions = this.defaultQueryOptions< |
| 291 | any, |
| 292 | any, |
| 293 | unknown, |
| 294 | any, |
| 295 | QueryKey |
| 296 | >({ queryKey }) |
| 297 | |
| 298 | const query = this.#queryCache.get<TInferredQueryFnData>( |
| 299 | defaultedOptions.queryHash, |
| 300 | ) |
| 301 | const prevData = query?.state.data |
| 302 | const data = functionalUpdate(updater, prevData) |
| 303 | |
| 304 | if (data === undefined) { |
| 305 | return undefined |
| 306 | } |
| 307 | |
| 308 | return this.#queryCache |
| 309 | .build(this, defaultedOptions) |
| 310 | .setData(data, { ...options, manual: true }) |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * Synchronous way to immediately update the cached data of multiple queries at once, using |