Skip to content

Commit

Permalink
fix component typing
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Sep 2, 2022
1 parent bfb9988 commit cdfb222
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/selfish-wolves-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@urql/preact': patch
'urql': patch
---

Update generics for components
7 changes: 4 additions & 3 deletions packages/preact-urql/src/components/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ export interface MutationState<
) => Promise<OperationResult<Data, Variables>>;
}

export function Mutation<Data = any, Variables = any>(
props: MutationProps<Data, Variables>
): VNode<any> {
export function Mutation<
Data = any,
Variables extends AnyVariables = AnyVariables
>(props: MutationProps<Data, Variables>): VNode<any> {
const mutation = useMutation<Data, Variables>(props.query);
return props.children({ ...mutation[0], executeMutation: mutation[1] });
}
7 changes: 4 additions & 3 deletions packages/preact-urql/src/components/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export interface QueryState<
executeQuery: (opts?: Partial<OperationContext>) => void;
}

export function Query<Data = any, Variables = any>(
props: QueryProps<Data, Variables>
): VNode<any> {
export function Query<
Data = any,
Variables extends AnyVariables = AnyVariables
>(props: QueryProps<Data, Variables>): VNode<any> {
const query = useQuery<Data, Variables>(props);
return props.children({ ...query[0], executeQuery: query[1] });
}
7 changes: 4 additions & 3 deletions packages/react-urql/src/components/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ export interface MutationState<
) => Promise<OperationResult<Data, Variables>>;
}

export function Mutation<Data = any, Variables = any>(
props: MutationProps<Data, Variables>
): ReactElement<any> {
export function Mutation<
Data = any,
Variables extends AnyVariables = AnyVariables
>(props: MutationProps<Data, Variables>): ReactElement<any> {
const mutation = useMutation<Data, Variables>(props.query);
return props.children({ ...mutation[0], executeMutation: mutation[1] });
}
7 changes: 4 additions & 3 deletions packages/react-urql/src/components/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export interface QueryState<
executeQuery: (opts?: Partial<OperationContext>) => void;
}

export function Query<Data = any, Variables = any>(
props: QueryProps<Data, Variables>
): ReactElement<any> {
export function Query<
Data = any,
Variables extends AnyVariables = AnyVariables
>(props: QueryProps<Data, Variables>): ReactElement<any> {
const query = useQuery<Data, Variables>(props);
return props.children({ ...query[0], executeQuery: query[1] });
}

0 comments on commit cdfb222

Please sign in to comment.