How can I show real-time post's replies/comments after a successful a reply mutation?
After submitting a successful reply mutation, I want to show a real-time UI update on my frontend?
7 Replies
Invalidate the query that fetches the replies
https://trpc.io/docs/client/react/useUtils#query-invalidation
useUtils | tRPC
useUtils is a hook that gives you access to helpers that let you manage the cached data of the queries you execute via @trpc/react-query. These helpers are actually thin wrappers around @tanstack/react-query's queryClient methods. If you want more in-depth information about options and usage patterns for useContext helpers than what we provide h...
after invalidating can those be fetched with an async caller ?
@BeBoRE
What do you mean by async caller? I assume you mean can you invalidate server-components? The answer is no, you'll need to refresh the page.
Functions: useRouter | Next.js
API reference for the useRouter hook.
if I used a client component will I need to refresh?
Thanks @BeBoRE !
No you don’t, if only use the query in client components just invalidate the query and you’ll be good.
Thanks!
Another question if thats okay, I want to use useMemo to cache fetched data in a client component,
how can I achieve that here:
React Query does this for you, there is no need to do this