How to handle optimistic update on image
Hello, I've implemented a feature for image uploading, and while it generally functions well, I'm facing a specific issue:
1. A user uploads an image.
2. An optimistic update is performed, and the new image is displayed.
3. The latest user state is refetched upon completion of the upload.
The problem arises after the user selects a file and the optimistic update occurs; all queries are refetched. I suspect this is due to a focus shift between the file selection dialog and the application. Consequently, the query refetch seems to override the optimistic update. Once the upload is finished, I use onSettle to fetch the latest state, where I then receive the final image which is correct.
Any insights on how to prevent the refetch from overriding the optimistic update would be greatly appreciated.
4 Replies
plain-purple•3y ago
I suspect this is due to a focus shift between the file selection dialog and the applicationthis is fixed in v5
wise-whiteOP•3y ago
ax i'm on react-query 3.39.3 lol and now even package name is not the same xD 😄
plain-purple•3y ago
seems like you're stuck in 2021
wise-whiteOP•3y ago
yeah migrated succesfully, and is ok i can confirm!!! will watch some tutorial today tho 😄