-
Notifications
You must be signed in to change notification settings - Fork 61
feat: add skip to usePreloadedQuery #99
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
base: main
Are you sure you want to change the base?
Conversation
|
Great call. I think you’re right. We need to add this or something like it. |
|
Another thing that sticks out is now everyone will need to handle undefined even if they never use Skipp. We could solve this with an overload (not my favorite) but on the surface it’s a breaking change right now. |
I agree. It will be more consistent and predictable since useQuery uses similar syntax. I will make the change. |
I already have an idea of how to address this. I will test it out when I got back home and let you know. |
5b26154 to
5b14938
Compare
5b14938 to
c3dd16d
Compare
|
@ianmacartney I just update the changes to what we've discussed. You were right. I don't see better way to handle capability other than overriding the function (which is what I implemented). Everything is working and tested in this repo. The only thing am a little unsure about is this: const result = useQuery(
skip
? (makeFunctionReference("_skip") as Query)
: (makeFunctionReference(preloadedQuery._name) as Query),
skip ? ("skip" as const) : args,
);where I have to create this dummy placeholder for |
As discussed in this discord thread, I've created a minimal demo repo to showcase the DX and UX differences between with/without skip option for
usePreloadedQueryThe primary motivation for this is it would be nice to have an elegant and intuitive api for waiting for auth token to be loaded on client without blocking other parts of the component. With current api, to achieve this you can create another client component and wrap it with
<Authenticated/>, but it becomes tedious in a lot of cases where you do not want to decouple the rendering logic to another component.before:
After:
Closes #98
I am not sure if I missed anything from documentation that can handle this more elegantly, but it is weird to me that you can skip
useQuerybut notusePreloadedQuery.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.