Skip to content
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

Dependent execution #407

Open
StorytellerCZ opened this issue Jun 21, 2024 · 4 comments
Open

Dependent execution #407

StorytellerCZ opened this issue Jun 21, 2024 · 4 comments

Comments

@StorytellerCZ
Copy link
Collaborator

I was recently looking at React Query and found in their docs that they have something called dependent queries:
https://tanstack.com/query/latest/docs/framework/react/guides/dependent-queries

I found this very interesting and something that I often find myself needing with the hooks, especially as it relates to user based content where I don't want to trigger a subscription and everything else if the user is not logged in or at least until that data is available. This could also be used with other conditional data and could help in reducing lot of boilerplate code to handle such scenarios or wait with execution until the given data is available so that I don't have a flash of 404 page and similar issues.

@radekmie
Copy link
Collaborator

Do you have anything in particular in mind? For example, useSubscribe already supports it, since the name (1st argument) is optional, and there's no subscription made if it's undefined.

@StorytellerCZ
Copy link
Collaborator Author

Interesting, that can be a workaround for the subscribe:

const userId = useUserId()
useSubscribe(userId ? undefined : 'get.profile')

But even with this the useFind or useTracker that follows would still execute, so it would be nice to prevent that if the condition isn't met.

@radekmie
Copy link
Collaborator

useFind also supports that via undefined and null in the result of the first argument. And useTrcker can just do an early return. Sure, there’s no extra prop, but it’s clear when read (I see and use it often).

@StorytellerCZ
Copy link
Collaborator Author

I'll experiment with it a bit and then I think we can add that to the documentation or guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants