T
TanStack17mo ago
plain-purple

204s - Null Or Undefined

When accessing via axios., a rest resource that could return an object or a 204 - no content. Is it better practice directly return the undefined from res?.data or manipulate that into a null for the consumer of the useQuery inside the queryFN.
i.e should the type be ResponseObject | undefined or ResponseObject | null. return res?.data or return res?.data ?? null
1 Reply
harsh-harlequin
harsh-harlequin17mo ago
You shouldn't return undefined from the queryFn. There should be a warning in dev mode if that happens

Did you find this page helpful?