Replies: 1 comment 1 reply
-
Instead of removing the optimistic change and adding the new one, you can replace it in a single mutate call or run mutate without data to trigger a revalidation, that will fetch the list again, this time with the new item, and it will replace the current list. |
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
-
Hello,
I'm trying to find a way to prevent SWR from re-rendering on each
mutate
call and instead re-render once after a batch ofmutate
callsI need this because I'm doing the following:
If I don't batch the last two changes, the item will be removed & re-added to the layout, causing the scroll position to shift
I can, instead of rollback then create, update the previously created element. But it makes the code way, way more complicated than just calling my "add item to list" function twice
For reference, this is what the code to add that list item looks like: https://gist.github.com/Ephys/5871cc905c03781bfa6356558ccaedba
Beta Was this translation helpful? Give feedback.
All reactions