TanStackT
TanStack3y ago
5 replies
nursing-lime

How to keep 'enabled' prop reactive when a Ref is passed

My code:
export const useSearchQuery = (input: Ref<string>) => useQuery({
  queryFn: async ({ signal }) => {
    const { data: { data } } = await fetchSearch(input.value, signal)

    return data
  },
  queryKey: [QUERY_KEYS.SEARCH_RESULT, input],
  enabled: // what goes here?

If I just pass !!input.value it isn't reactive, and if I pass !!input it's always true. How do I avoid triggering a fetch when the input is an empty string?
Was this page helpful?