This commit is contained in:
@ -29,7 +29,7 @@ export const queryKeys = {
|
||||
export const usePhotos = () => {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.photos,
|
||||
queryFn: () => api.get('/photos'),
|
||||
queryFn: (): Promise<Photo[]> => api.get('/photos'),
|
||||
staleTime: 5 * 60 * 1000, // 5分钟内不重新获取
|
||||
})
|
||||
}
|
||||
@ -38,7 +38,7 @@ export const usePhotos = () => {
|
||||
export const usePhoto = (id: number) => {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.photo(id),
|
||||
queryFn: () => api.get(`/photos/${id}`),
|
||||
queryFn: (): Promise<Photo> => api.get(`/photos/${id}`),
|
||||
enabled: !!id,
|
||||
})
|
||||
}
|
||||
@ -47,7 +47,7 @@ export const usePhoto = (id: number) => {
|
||||
export const useCategories = () => {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.categories,
|
||||
queryFn: () => api.get('/categories'),
|
||||
queryFn: (): Promise<string[]> => api.get('/categories'),
|
||||
staleTime: 10 * 60 * 1000, // 10分钟内不重新获取
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user