Tiger 🐅
Tiger 🐅3w ago

Optimistic update workflow

call, show something as pending, but redirect when its done? 🤔
5 Replies
lee
lee3w ago
const m = useMutation(api.foo.bar)
.withOptimisticUpdate(... code that marks query result as pending ...);

useEffect(() => {
m().then((result) => redirect());
});
const m = useMutation(api.foo.bar)
.withOptimisticUpdate(... code that marks query result as pending ...);

useEffect(() => {
m().then((result) => redirect());
});
Tiger 🐅
Tiger 🐅OP3w ago
oh i was await it after the await calling redirect that didnt work this is good i could add a temporary one and show it ill battle with this in my next side project almost done with current one
lee
lee3w ago
Awaiting also works. That's effectively what the .then is doing
Tiger 🐅
Tiger 🐅OP3w ago
i know thats why i was confused why it didnt work im awaiting the update optimistic + redirect is done at the same tim
lee
lee3w ago
That's unexpected. Could you share the code

Did you find this page helpful?