Created
March 26, 2025 01:59
-
-
Save nixjs/3ec5578889b7d5d4bd412787f928a0be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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