(
query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,
options: QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey
>,
)
| 450 | } |
| 451 | |
| 452 | protected createResult( |
| 453 | query: Query<TQueryFnData, TError, TQueryData, TQueryKey>, |
| 454 | options: QueryObserverOptions< |
| 455 | TQueryFnData, |
| 456 | TError, |
| 457 | TData, |
| 458 | TQueryData, |
| 459 | TQueryKey |
| 460 | >, |
| 461 | ): QueryObserverResult<TData, TError> { |
| 462 | const prevQuery = this.#currentQuery |
| 463 | const prevOptions = this.options |
| 464 | const prevResult = this.#currentResult as |
| 465 | | QueryObserverResult<TData, TError> |
| 466 | | undefined |
| 467 | const prevResultState = this.#currentResultState |
| 468 | const prevResultOptions = this.#currentResultOptions |
| 469 | const queryChange = query !== prevQuery |
| 470 | const queryInitialState = queryChange |
| 471 | ? query.state |
| 472 | : this.#currentQueryInitialState |
| 473 | |
| 474 | const { state } = query |
| 475 | let newState = { ...state } |
| 476 | let isPlaceholderData = false |
| 477 | let data: TData | undefined |
| 478 | |
| 479 | // Optimistically set result in fetching state if needed |
| 480 | if (options._optimisticResults) { |
| 481 | const mounted = this.hasListeners() |
| 482 | |
| 483 | const fetchOnMount = !mounted && shouldFetchOnMount(query, options) |
| 484 | |
| 485 | const fetchOptionally = |
| 486 | mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions) |
| 487 | |
| 488 | if (fetchOnMount || fetchOptionally) { |
| 489 | newState = { |
| 490 | ...newState, |
| 491 | ...fetchState(state.data, query.options), |
| 492 | } |
| 493 | } |
| 494 | if (options._optimisticResults === 'isRestoring') { |
| 495 | newState.fetchStatus = 'idle' |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | let { error, errorUpdatedAt, status } = newState |
| 500 | |
| 501 | // Per default, use query data |
| 502 | data = newState.data as unknown as TData |
| 503 | let skipSelect = false |
| 504 | |
| 505 | // use placeholderData if needed |
| 506 | if ( |
| 507 | options.placeholderData !== undefined && |
| 508 | data === undefined && |
| 509 | status === 'pending' |
no test coverage detected