(
query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,
options: QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey
>,
)
| 426 | } |
| 427 | |
| 428 | protected createResult( |
| 429 | query: Query<TQueryFnData, TError, TQueryData, TQueryKey>, |
| 430 | options: QueryObserverOptions< |
| 431 | TQueryFnData, |
| 432 | TError, |
| 433 | TData, |
| 434 | TQueryData, |
| 435 | TQueryKey |
| 436 | >, |
| 437 | ): QueryObserverResult<TData, TError> { |
| 438 | const prevQuery = this.#currentQuery |
| 439 | const prevOptions = this.options |
| 440 | const prevResult = this.#currentResult as |
| 441 | | QueryObserverResult<TData, TError> |
| 442 | | undefined |
| 443 | const prevResultState = this.#currentResultState |
| 444 | const prevResultOptions = this.#currentResultOptions |
| 445 | const queryChange = query !== prevQuery |
| 446 | const queryInitialState = queryChange |
| 447 | ? query.state |
| 448 | : this.#currentQueryInitialState |
| 449 | |
| 450 | const { state } = query |
| 451 | let newState = { ...state } |
| 452 | let isPlaceholderData = false |
| 453 | let data: TData | undefined |
| 454 | |
| 455 | // Optimistically set result in fetching state if needed |
| 456 | if (options._optimisticResults) { |
| 457 | const mounted = this.hasListeners() |
| 458 | |
| 459 | const fetchOnMount = !mounted && shouldFetchOnMount(query, options) |
| 460 | |
| 461 | const fetchOptionally = |
| 462 | mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions) |
| 463 | |
| 464 | if (fetchOnMount || fetchOptionally) { |
| 465 | newState = { |
| 466 | ...newState, |
| 467 | ...fetchState(state.data, query.options), |
| 468 | } |
| 469 | } |
| 470 | if (options._optimisticResults === 'isRestoring') { |
| 471 | newState.fetchStatus = 'idle' |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | let { error, errorUpdatedAt, status } = newState |
| 476 | |
| 477 | // Per default, use query data |
| 478 | data = newState.data as unknown as TData |
| 479 | let skipSelect = false |
| 480 | |
| 481 | // use placeholderData if needed |
| 482 | if ( |
| 483 | options.placeholderData !== undefined && |
| 484 | data === undefined && |
| 485 | status === 'pending' |
no test coverage detected