Skip to content

Commit

Permalink
convert to useCallback this reduces the function allocations by 1 for…
Browse files Browse the repository at this point in the history
… each useQuery/useSubscription (#504)
  • Loading branch information
JoviDeCroock authored and kitten committed Jan 13, 2020
1 parent e06098d commit 2fb68ee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/hooks/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const useQuery = <T = any, V = object>(
const request = useRequest(args.query, args.variables);

// Create a new query-source from client.executeQuery
const makeQuery$ = useMemo(
() => (opts?: Partial<OperationContext>) => {
const makeQuery$ = useCallback(
(opts?: Partial<OperationContext>) => {
return client.executeQuery(request, {
requestPolicy: args.requestPolicy,
pollInterval: args.pollInterval,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export const useSubscription = <T = any, R = T, V = object>(
const request = useRequest(args.query, args.variables);

// Create a new subscription-source from client.executeSubscription
const makeSubscription$ = useMemo(
() => (opts?: Partial<OperationContext>) => {
const makeSubscription$ = useCallback(
(opts?: Partial<OperationContext>) => {
return client.executeSubscription(request, { ...args.context, ...opts });
},
[client, request, args.context]
Expand Down

0 comments on commit 2fb68ee

Please sign in to comment.