Skip to content

Commit

Permalink
fix: [DHIS2] Type generic T = QueryResult to useDataQuery (#1297)
Browse files Browse the repository at this point in the history
* fix: added generic T = QueryResult

* fix: changed to correct import

* fix: prettier

* fix: changed name of T

* fix: prettier
  • Loading branch information
eirikhaugstulen authored May 2, 2023
1 parent 1d018a8 commit 7c5c083
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 8 additions & 3 deletions services/data/src/react/hooks/useDataQuery.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { useState, useRef, useCallback, useDebugValue } from 'react'
import { useQuery, setLogger } from 'react-query'
import type { Query, QueryOptions, QueryVariables } from '../../engine'
import type {
Query,
QueryOptions,
QueryResult,
QueryVariables,
} from '../../engine'
import type { FetchError } from '../../engine/types/FetchError'
import type { QueryRenderInput, QueryRefetchFunction } from '../../types'
import { mergeAndCompareVariables } from './mergeAndCompareVariables'
Expand Down Expand Up @@ -28,15 +33,15 @@ type QueryState = {
refetchCallback?: (data: any) => void
}

export const useDataQuery = (
export const useDataQuery = <TQueryResult = QueryResult>(
query: Query,
{
onComplete: userOnSuccess,
onError: userOnError,
variables: initialVariables = {},
lazy: initialLazy = false,
}: QueryOptions = {}
): QueryRenderInput => {
): QueryRenderInput<TQueryResult> => {
const [staticQuery] = useStaticInput<Query>(query, {
warn: true,
name: 'query',
Expand Down
7 changes: 4 additions & 3 deletions services/data/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ export interface ExecuteHookResult<ReturnType> {
data?: ReturnType
}

export interface QueryState {
export interface QueryState<TQueryResult> {
called: boolean
loading: boolean
fetching: boolean
error?: FetchError
data?: QueryResult
data?: TQueryResult
}

export interface QueryRenderInput extends QueryState {
export interface QueryRenderInput<TQueryResult = QueryResult>
extends QueryState<TQueryResult> {
engine: DataEngine
refetch: QueryRefetchFunction
}
Expand Down

0 comments on commit 7c5c083

Please sign in to comment.