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

Setting custom queryKey in useFetchNotifications #5803

Closed
1 of 4 tasks
samya-ak opened this issue Jun 23, 2024 · 2 comments
Closed
1 of 4 tasks

Setting custom queryKey in useFetchNotifications #5803

samya-ak opened this issue Jun 23, 2024 · 2 comments
Labels

Comments

@samya-ak
Copy link

  • I'm submitting a...

    • bug report
    • feature request
    • question about the decisions made in the repository
    • question about how to use this project
  • Summary
    I'm trying to fetch all notifications and only unread notifications separately.
    I'm doing something like

const {
    data: unreadData,
    isLoading: isUnreadLoading,
    hasNextPage: hasUnreadNextPage,
    fetchNextPage: fetchUnreadNextPage,
  } = useFetchNotifications(
    {
      query: {
        limit: 10,
        read: false,
      },
    },
    {
      refetchOnMount: true,
      refetchOnWindowFocus: true,
      onError: (err) => handleError(err),
    }
  );

  const {
    data: allData,
    isLoading: isAllLoading,
    hasNextPage: hasAllNextPage,
    fetchNextPage: fetchAllNextPage,
  } = useFetchNotifications(
    { query: { limit: 10 } },
    {
      refetchOnMount: true,
      refetchOnWindowFocus: true,
      onError: (err) => handleError(err),
    }
  );

I believe useInfiniteQuery underneath useFetchNotifications is using infinite_notifications as queryKey for both requests. Hence, returning the same cached notifications. I was wondering if there's a way to modify the queryKey for each request to fetch all notifications and unread notifications in separate requests.

Thanks!

Copy link

linear bot commented Jun 23, 2024

@samya-ak
Copy link
Author

samya-ak commented Jun 23, 2024

Ended up using separate NovuProvider for each useFetchNotifications for now.
Only downside I see is not being able to take advantage of caching and context since I'm conditionally rendering the providers.
Open to better suggestions : )

@linear linear bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant