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