I am using a graphql HOC
with mutation for a input type of checkbox
. I have also added optimistic UI update option to it. Checking the box will fire a mutation with value=true
and unchecking will fire a mutation with value=false
.
But the problem is rapid clicking results in multiple mutation calls to the server and there is a latency in responses. Meanwhile optimisticResponse
update does its job and toggles the checkbox. When server response arrives, update function is called again and it toggles checkbox resulting in glitch in UI.
Let me summarize the flow I could anticipate
Order of clicks:
Check => Uncheck => Check
Order of UI updates:
Check(optimistic response) => Uncheck(optimistic response) => Check(server response) => Check(Optimistic response) => Uncheck(server response) => Check(server response)
Is there any way to remove these glitches?