Kıte
Kıte4mo ago

withOptimistic in fetchMutation

Is there a way to use withOptimistic in fetchMutation? I tried to usereact useOptimistic hooks with preloadQuery but
Preload<typeof api.dbquery>
Preload<typeof api.dbquery>
somehow _id and _createdTime is required in new obj.
7 Replies
ballingt
ballingt4mo ago
fetchMutation is generally for server side functions, it sounds like you want to apply that optmistic update and have it SSR'd for initial page load?
Kıte
KıteOP4mo ago
I created a realtime chat in ssr, I also used convexNextAuthToken for that to work. I don't know how I can apply optimistic update when user send a message.
ballingt
ballingt4mo ago
I don't quite know what this means, is it client-side chat that initially SSRs? Or does "realtime chat in ssr" mean server components? usually known as "RSCs"
Kıte
KıteOP4mo ago
Yup, its a client side chat that initially SSR Im using convexAuth with ssr
ballingt
ballingt4mo ago
Ah I see, you want ti use useOptimistic. Instead you should use Convex's optimistic update solution, adding optimistic updates to the useMutation return value. Convex has a more powerful optimistic update system built in. But if you want to use useOptimistic, just make up a _id and a _createdAt time.
jamwt
jamwt4mo ago
Optimistic Updates | Convex Developer Hub
Even though Convex queries are completely reactive, sometimes you'll want to
Kıte
KıteOP4mo ago
Can I use convexNextAuthToken in useMutation? using app router with ssa. I also tried this, but somehow it duplicate my message. I'll test more outcome, I'll update after some test.

Did you find this page helpful?