Olamide
Olamide
CCConvex Community
Created by Olamide on 9/12/2024 in #support-community
How do I skip queries when using convex with tanstack query.
I am passing a conditional boardId but only want the query to run if and only if the boardId is present. I have tried all these but none of them work:
import { convexQuery, useConvexMutation } from '@convex-dev/react-query';
import { useQuery, useMutation, skipToken } from '@tanstack/react-query';

// Trial one
export const useGetBoardById = (id?: Id<'boards'>) => {
return useQuery(
convexQuery(api.frontend.boards.getBoardById, id ? { id } : 'skip'),
);
};

// Trial two.

export const useGetBoardById = (id?: Id<'boards'>) => {
return useQuery({
queryFn: id
? convexQuery(api.frontend.boards.getBoardById, { id }).queryFn
: skipToken,
queryKey: convexQuery(api.frontend.boards.getBoardById, { id: id! })
.queryKey,
staleTime: convexQuery(api.frontend.boards.getBoardById, { id: id! })
.staleTime,
enabled: !!id,
});
};


//Trial three
export const useGetBoardById = (id?: Id<'boards'>) => {
return useQuery({
...convexQuery(api.frontend.boards.getBoardById, { id: id! }),
enabled: !!id,
});
};
import { convexQuery, useConvexMutation } from '@convex-dev/react-query';
import { useQuery, useMutation, skipToken } from '@tanstack/react-query';

// Trial one
export const useGetBoardById = (id?: Id<'boards'>) => {
return useQuery(
convexQuery(api.frontend.boards.getBoardById, id ? { id } : 'skip'),
);
};

// Trial two.

export const useGetBoardById = (id?: Id<'boards'>) => {
return useQuery({
queryFn: id
? convexQuery(api.frontend.boards.getBoardById, { id }).queryFn
: skipToken,
queryKey: convexQuery(api.frontend.boards.getBoardById, { id: id! })
.queryKey,
staleTime: convexQuery(api.frontend.boards.getBoardById, { id: id! })
.staleTime,
enabled: !!id,
});
};


//Trial three
export const useGetBoardById = (id?: Id<'boards'>) => {
return useQuery({
...convexQuery(api.frontend.boards.getBoardById, { id: id! }),
enabled: !!id,
});
};
Thank you in advance
8 replies
CCConvex Community
Created by Olamide on 8/20/2024 in #support-community
How Can We Collaborate Across Multiple Repos on the Same Convex Instance?
Our team has recently adopted Convex for our database, primarily due to its speed and real-time capabilities. We're maintaining a custom backend built with Node.js for our business logic, while our front end is being developed using Next.js. We've encountered an issue where the most recent npx convex dev command called from either the frontend or backend overwrites the existing functions in the Convex dashboard, rather than merging them. This is causing conflicts as both teams need to create and manage Convex queries and mutations independently. Is there a way to set up our environment so that both the frontend and backend teams can work on the same Convex instance without overwriting each other's work? Any guidance or best practices would be greatly appreciated.
1 replies