Skip to content

Instantly share code, notes, and snippets.

@nixjs
Created March 26, 2025 01:59
Show Gist options
  • Save nixjs/3ec5578889b7d5d4bd412787f928a0be to your computer and use it in GitHub Desktop.
Save nixjs/3ec5578889b7d5d4bd412787f928a0be to your computer and use it in GitHub Desktop.
import { useQuery } from '@tanstack/react-query'
import { Category } from '@/model/category'
import * as CategoryApi from '@/utils/axios/category'
export default function useCategoryFetcher(categoryId?: string) {
const { data, refetch, isLoading, error } = useQuery<
Category[] | Category,
Error
>({
queryKey: ['category', categoryId],
queryFn: () => {
return !categoryId
? CategoryApi.findAllRequest()
: CategoryApi.findRequest(categoryId)
},
enabled: false,
})
return { data, refetch, isLoading, error }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment