-
I have a list of posts, I delete one, then in the onSuccess mutation option I invalidate the posts list. This works great when there are a lot of posts, but when there's only one single post left that gets deleted, it calls the api because query invalidation and the api throws an 404 error "No posts found" because there are none left. The error shows in frontend, all good, but it also shows the single last post because I guess RQ doesn't remove data on error, but in this case I need it removed. How would I handle this? Is there an easy way or should I add a specific case in the onError option for the entire posts list query? Thank you. LE: i think i've solved it? To map posts i was using {data && posts.map...} because i've seen someone do this. I've switched to {isSuccess && posts.map...} and now it's ok. I really need to understand statuses better and when they occur in the process, seems to me they have a few little gotchas |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If errors are more important than stale data, I would just check for the error first in the component. Have a read here: https://tkdodo.eu/blog/status-checks-in-react-query that said, I think it’s pretty weird for a list endpoint to return 404 instead of 200 with an empty list 🤷♂️ |
Beta Was this translation helpful? Give feedback.
If errors are more important than stale data, I would just check for the error first in the component. Have a read here: https://tkdodo.eu/blog/status-checks-in-react-query
that said, I think it’s pretty weird for a list endpoint to return 404 instead of 200 with an empty list 🤷♂️