import { useQuery } from '@tanstack/react-query'
import { getUser } from '../api/getUser'

export const userQueryKey = (id: number) => ['users', id] as const

export function useUser(id: number) {
  return useQuery({
    queryKey: userQueryKey(id),
    queryFn: () => getUser(id),
    staleTime: 15_000,
    enabled: id > 0,
  })
}
