Update local data from useQuery

am using trpc to make a query to load recipe information in my nextjs application: const { data, isLoading } = api.recipes.getDetails.useQuery({ id: id }); I also have a mutation to update the recipe: const { mutateAsync: updateRecipe } = api.recipes.update.useMutation({}); How can I update the local state of data (that comes from the getDetails query) without having to refetch that data once the mutation response comes back? Here is my mutation handler:
await updateRecipe(updatedRecipe, {
onSuccess(data, variables, context) {
console.log(JSON.stringify(data));
!!data && updateLocalData();
},
});
await updateRecipe(updatedRecipe, {
onSuccess(data, variables, context) {
console.log(JSON.stringify(data));
!!data && updateLocalData();
},
});
I would like to implement updateLocalData() but not sure how to set the data without refetching
A
AldiBoi96d ago
Stack Overflow
How to revalidate after mutation with react-query?
I've a basic implementation of data fetching and updating using react-query on next.js app. My goal is to update the data after mutation. Currently the data updates only on tab refresh. But without...
A
AldiBoi96d ago
I believe trpc hides the queryKey thats used in its wrapping of react-query, so next steps would be to find out how to re-expose it
A
AldiBoi96d ago
getQueryKey | tRPC
We provide a getQueryKey helper that accepts a router or procedure so that you can easily provide the native function the correct query key.
T
tyler494996d ago
Thank you! Will take a look
M
Matt84d ago
as of now with the app arouter is it difficult to revalidate data iwth query keys?
Want results from more Discord servers?
Add your server
More Posts
Vercel stream keep alive???I just found this git repo for publishing messages with NextJS and Upstash and I got some questions.Where to suggest stream topicsIs there somewhere Theo likes to take suggestions for video/stream topics? I'm curious what people Nextjs SEO and Google Rank advice...Hi guys, so I'm trying to learn how the Google Rank work. I'm working on a big ecommerce site, andTheo uses api.posts.getAll.useQuery() in T3 tutorial video, but T3 app only has .query() calls.Where did Theo got .useQuery() methods? I only have .query() https://youtu.be/YkOSUVzOAA4?t=2211`tsx ./src/server/db/SCRIPT_NAME` doesn't recognize environment variables.I created a db migrator script similar to the recommendations here: https://create.t3.gg/en/usage/prHow can I specify a `callbackUrl` when using the default NextAuth setup?I'm using the default NextAuth setup (going to /api/auth/signin to get users to sign in), and I wantserver side auth & react queryI am migration a old project that used t3 & nextjs 12. I have removed the old t3-stuff, such as ``sePassing config prop to zod schema for dynamic refinementPlease correct me if i am approaching this from the wrong perspective, im building a form with a calmissing filesI recently npm installed and followed along the video to double check. I am missing my _app.tsx fileWhat are some T3 community recommendations for a toast library?Is Toastify still a good option?Pre-rendered page + dynamic contentI have a list of pre-rendered (at build time) `public` articles. But then I want to check if there i[Turborepo] TypeError: Cannot read properties of undefined (reading 'push')``` www:dev: TypeError: Cannot read properties of undefined (reading 'push') www:dev: at writeCoradix - slack or discordDoes anyone know if there's a Discord or Slack for asking questions regarding radix-ui, or should I What is the name of this?I would like to know what the name is of something like this in the picture. Because I want to look Best advice to get a Full stack job in 2024Hi I terribly need some carreer advices/insights about job hunting, I recently graduated from a CS NextAuth and role based access controlCan someone explain to me how to modify the the auth.ts file in the server folder when you set up a