T
TanStack3y ago
optimistic-gold

placeholderData with useQuery returned data property type

I am using placeholderData in my query but the type for data returned seems to have undefined still in it. I notice when setting initialData it correctly removes the undefined from the type but with placeholderData it doesn't. I'm guessing this is done for a reason. Can anyone tell me why it could be undefined still with a placeholder set?
No description
No description
1 Reply
like-gold
like-gold3y ago
there is no type narrowing for placeholderData. If the query errors out, data will still be undefined. I've written about that here: https://tkdodo.eu/blog/placeholder-and-initial-data-in-react-query

Did you find this page helpful?