-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
RTK-QueryIssues related to Redux-Toolkit-QueryIssues related to Redux-Toolkit-QueryTypeScriptIssues related to TypeScript.Issues related to TypeScript.
Description
Hello! I wrote a hook to unify calling all query and mutation APIs from the store in the current React context. My hook takes three parameters: the API endpoint path, the params, and the options. Since the options type is not exported directly, I have to use Parameters on TypedUseQuery to infer the Options type. It would be more convenient if the Options type could be exported directly.
type UseQuery<T extends EndpointDefinitions> = <
K extends keyof T & string,
Definition extends NonNullable<T[K]['Types']> = NonNullable<T[K]['Types']>,
>(
path: K,
arg?: Definition['QueryArg'],
options?: Parameters<TypedUseQuery<Definition['ResultType'], Definition['QueryArg'], Definition['BaseQuery']>>[1],
) => TypedUseQueryHookResult<Definition['ResultType'], Definition['QueryArg'], Definition['BaseQuery']>;
const { data: data1 } = useQuery('api1.getUser', { id: 1 }, { refetchOnFocus: true });
const { data: data2 } = useQuery('api2.getStar', { id: 2 }, { refetchOnFocus: true });If permitted, I could also submit a PR. Thank you!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
RTK-QueryIssues related to Redux-Toolkit-QueryIssues related to Redux-Toolkit-QueryTypeScriptIssues related to TypeScript.Issues related to TypeScript.