-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Summary
Small change, but imo with great DX: inject variables and queryClient into initialData / placeholderData functions.
Motivation
With usual REST API structure, it's not uncommon to have this type of endpoints:
/teams - gets all teams
/teams/${id} - gets specific team data
With that, I found it useful to do this query structure
export const useAllTeams = () => useQuery({
queryKey: ['teams'],
queryFn: () => client.get('/teams'),
});
export const useTeam = (id: string) => {
const queryClient = useQueryClient();
return useQuery({
queryKey: ['teams', { id }],
queryFn: () => client.get(`/teams/${id}`),
initialData: () => queryClient.getQueryData(['teams']).find(team => team.id === id),
})
}Unfortunately, with how router / createQuery are currently implemented, there's no way to recreate that.
Is there some room to create / approve such change? I could implement it and submit a PR, if you see it fit the package
54m1r, hugosajama-ae and a29paul
Metadata
Metadata
Assignees
Labels
No labels