Can I update cache on onSettled
hook?
#2800
Unanswered
jimmiejackson414-zz
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Code looks good, can you reproduce it in a sandbox? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on adding optimistic updates to eliminate excessive network requests. I have extracted the giant method out of the component and in to a separate service file. So far my code looks like this:
Todos.tsx:
todos.service.ts:
Everything within the
onMutate
hook works fine, however the issue I'm running in to is that the id of the optimistically created Todo is having to be randomly generated.So in the scenario where a user creates a new Todo but then tries to immediately delete it, a Todo with that randomly generated ID wouldn't actually exist in the DB. I need to be able to replace that item in the
onSettled
hook, but looking at the Devtools the code I currently have there doesn't appear to be working. I also don't receive any errors. Any ideas out there?Beta Was this translation helpful? Give feedback.
All reactions