-
-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passing a custom client instance. #446
Conversation
@@ -33,7 +35,7 @@ export const useQuery = <T = any, V = object>( | |||
args: UseQueryArgs<V> | |||
): UseQueryResponse<T> => { | |||
const unsubscribe = useRef(noop); | |||
const client = useClient(); | |||
const client = useClient(args.client); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh before I forget 😅 let’s get this added to the other hooks as well.
useSubscription
will just need another arg, just like useQuery
. For useMutation
we can probably use an optional second argument.
Apologies for keeping this around for so long! I think for now we won't end up merging this, sorry! 😞 Mainly we're concerned that this will A) make not a lot of sense as a natural evolution of the hook, and B) be an irreversible API change that is not inline with React. I'll post another comment in the issue. |
I also stumbled upon this problem and ended up having to wrap my component into another urql.Provider to support this usecase. This is not ideal as it means the children hierarchy of the wrapped component has a different provider, and this might be unexpected for the children (in my case it's fine, the component is very small and its children do not use useQuery). It would be much simpler if useQuery and consorts could accept a client parameter. @kitten Can you expand on why this would not be natural for this hook and why it would not be inline with React ? |
Resolve #429
Hi there. Apparently this came up with another user too: #429
I had the same need so instead of continuing to roll a custom useQuery hook I thought I'd write a quick PR.