T
TanStack2y ago
unwilling-turquoise

how to define types for querykey?

Hello, a lot of times when I end up with some bugs in my app, i noticed that I was always using wrong querykey with methods such as setQueryData and I was wondering, is there a way to define the types, so that when I use setQueryData I would know that im entering correct queryKey.
export function useGetWeeklyDiaryNew(
userId: string | undefined | null,
startDate: string,
endDate: string
) {
return useQuery({
queryKey: [
'weeklyDiary',
{
userId,
startDate,
endDate
}
],
export function useGetWeeklyDiaryNew(
userId: string | undefined | null,
startDate: string,
endDate: string
) {
return useQuery({
queryKey: [
'weeklyDiary',
{
userId,
startDate,
endDate
}
],
1 Reply
deep-jade
deep-jade2y ago
The Query Options API
v5 brought a new, powerful API, especially if you're using React Query with TypeScript...

Did you find this page helpful?