withOptimistic in fetchMutation
Is there a way to use withOptimistic in fetchMutation?
I tried to usereact useOptimistic hooks with preloadQuery but somehow _id and _createdTime is required in new obj.
7 Replies
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?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.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"
Yup, its a client side chat that initially SSR
Im using convexAuth with ssr
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.
Optimistic Updates | Convex Developer Hub
Even though Convex queries are completely reactive, sometimes you'll want to
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.