(
query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,
options: QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey
>,
)
| 557 | } |
| 558 | |
| 559 | protected createResult( |
| 560 | query: Query<TQueryFnData, TError, TQueryData, TQueryKey>, |
| 561 | options: QueryObserverOptions< |
| 562 | TQueryFnData, |
| 563 | TError, |
| 564 | TData, |
| 565 | TQueryData, |
| 566 | TQueryKey |
| 567 | >, |
| 568 | ): QueryObserverResult<TData, TError> { |
| 569 | const prevQuery = this.#currentQuery |
| 570 | const prevOptions = this.options |
| 571 | const prevResult = this.#currentResult as |
| 572 | | QueryObserverResult<TData, TError> |
| 573 | | undefined |
| 574 | const prevResultState = this.#currentResultState |
| 575 | const prevResultOptions = this.#currentResultOptions |
| 576 | const queryChange = query !== prevQuery |
| 577 | const queryInitialState = queryChange |
| 578 | ? query.state |
| 579 | : this.#currentQueryInitialState |
| 580 | |
| 581 | const { state } = query |
| 582 | let newState = { ...state } |
| 583 | let isPlaceholderData = false |
| 584 | let data: TData | undefined |
| 585 | |
| 586 | // Optimistically set result in fetching state if needed |
| 587 | if (options._optimisticResults) { |
| 588 | const mounted = this.hasListeners() |
| 589 | |
| 590 | const fetchOnMount = !mounted && shouldFetchOnMount(query, options) |
| 591 | |
| 592 | const fetchOptionally = |
| 593 | mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions) |
| 594 | |
| 595 | if (fetchOnMount || fetchOptionally) { |
| 596 | newState = { |
| 597 | ...newState, |
| 598 | ...fetchState(state.data, query.options), |
| 599 | } |
| 600 | } |
| 601 | if (options._optimisticResults === 'isRestoring') { |
| 602 | newState.fetchStatus = 'idle' |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | let { error, errorUpdatedAt, status } = newState |
| 607 | |
| 608 | // Per default, use query data |
| 609 | data = newState.data as unknown as TData |
| 610 | let skipSelect = false |
| 611 | |
| 612 | // use placeholderData if needed |
| 613 | if ( |
| 614 | options.placeholderData !== undefined && |
| 615 | data === undefined && |
| 616 | status === 'pending' |
no test coverage detected