* Computes the result for a query and options from the query's state, applying `select`, * `placeholderData`, and the derived flags. Subclasses override it to add their own fields. * @param query - The query to compute the result for. * @param options - The observer options to compute the r
(
query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,
options: QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey
>,
)
| 587 | * @returns The computed result. |
| 588 | */ |
| 589 | protected createResult( |
| 590 | query: Query<TQueryFnData, TError, TQueryData, TQueryKey>, |
| 591 | options: QueryObserverOptions< |
| 592 | TQueryFnData, |
| 593 | TError, |
| 594 | TData, |
| 595 | TQueryData, |
| 596 | TQueryKey |
| 597 | >, |
| 598 | ): QueryObserverResult<TData, TError> { |
| 599 | const prevQuery = this.#currentQuery |
| 600 | const prevOptions = this.options |
| 601 | const prevResult = this.#currentResult as |
| 602 | | QueryObserverResult<TData, TError> |
| 603 | | undefined |
| 604 | const prevResultState = this.#currentResultState |
| 605 | const prevResultOptions = this.#currentResultOptions |
| 606 | const queryChange = query !== prevQuery |
| 607 | const queryInitialState = queryChange |
| 608 | ? query.state |
| 609 | : this.#currentQueryInitialState |
| 610 | |
| 611 | const { state } = query |
| 612 | let newState = { ...state } |
| 613 | let isPlaceholderData = false |
| 614 | let data: TData | undefined |
| 615 | |
| 616 | // Optimistically set result in fetching state if needed |
| 617 | if (options._optimisticResults) { |
| 618 | const mounted = this.hasListeners() |
| 619 | |
| 620 | const fetchOnMount = !mounted && shouldFetchOnMount(query, options) |
| 621 | |
| 622 | const fetchOptionally = |
| 623 | mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions) |
| 624 | |
| 625 | if (fetchOnMount || fetchOptionally) { |
| 626 | newState = { |
| 627 | ...newState, |
| 628 | ...fetchState(state.data, query.options), |
| 629 | } |
| 630 | } |
| 631 | if (options._optimisticResults === 'isRestoring') { |
| 632 | newState.fetchStatus = 'idle' |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | let { error, errorUpdatedAt, status } = newState |
| 637 | |
| 638 | // Per default, use query data |
| 639 | data = newState.data as unknown as TData |
| 640 | let skipSelect = false |
| 641 | |
| 642 | // use placeholderData if needed |
| 643 | if ( |
| 644 | options.placeholderData !== undefined && |
| 645 | data === undefined && |
| 646 | status === 'pending' |
no test coverage detected