No way to do optimistic updates with multiple queries - next query based on optimistic previous one #6202
Replies: 3 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
I opened it
Agree - its better to do it only onSetteld:() => {}
No - I don't want to lock value - as I mentioned it doesn't matter previous response from server was successfull for not - I do new request to DB based on last optimistic update (so if user will click from 1 to 10 and it fails on 7 (for example) - it doesn't matter because last update from 9 to 10 will successfull (if not it will be 9)) tbh - I not believe that my conversation with you comes to react-query update/improvement - so close this (also for me you speak like on another language - in some points I totally don't undestand you) |
Beta Was this translation helpful? Give feedback.
-
I have a similar question, but in my case multiple requests to modify the same query. Here's the simplified example:
and it's CRUD for each Object, e.g. during one phase multiple CREATE, UPDATE, and DELETE could happen triggering, e.g. 6 different queries that would modify the same |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
Now it works only for single query like send message - like / unklike
but I want to implement functionality when user click on + button multiple times and product quantity should be increased optimistically multiple times as well
Your minimal, reproducible example
https://github.com/nicitaacom/acc2-react-query/blob/development/app/components/ToDoCard.tsx
codesandbox doesn't work (at least today or with last 'dev container' update)
stackblitz - has no way to edit in vs code
Steps to reproduce
here is how I do logic (nvm that query names todos but I change on_stock - its just example)
Expected behavior
decribed above
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
"@tanstack/react-query": "^5.0.0",
"@tanstack/react-query-devtools": "^5.0.0",
"next": "13.5.6-canary.6",
Tanstack Query adapter
react-query
TanStack Query version
above
TypeScript version
Additional context
When I open my dev tools - network - I see there are 2+ queries (depends on how much time I clicked the button) - but this queries the same - for example to increase by 1 from 23 to 24 and in optimistic UI I see already 25 but after ~8 seconds I see 24 because its 2 the same queries to increase quantity from 23 to 24 - so I want second query to be optimistic based on previous query - and if any previous query throws error - display UI with all successfull queries e.g from 23 to 25 - if from 25 to 26 throws error display 25 (not 23 or 24) - otherwise display 26 - also next query should have higher priority than previous one - I would say that I may cancel previous query and make new one based on optimistic UI changes (If it doesn't depend on the result from the previous one, like in blockchain, in my case it's just increasing count, so that's fine)
I know I described it complicated - in 2 words make next query based on result of previous optimistic query
Temp solution I found - create state
I created state to optimisticaly update this state and make next query based on optimistically updated previous one
It looks a bit complicated - I know - you may suggest how to improve this
Beta Was this translation helpful? Give feedback.
All reactions