Add `trpc.useContext().setQueryData()` callback
See original GitHub issueWhen updating values in the query cache which rely upon the old value, an updater callback comes handy, e.g.:
setQueryData(
["Page.findAllBySiteId", data.siteId],
(prev) => [...prev, data],
);
Instead of:
const prevPagesBySiteId =
getQueryData(["Page.findBySiteId", data.siteId]) ?? [];
setQueryData(
["Page.findAllBySiteId", data.siteId],
[...prevPagesBySiteId, data],
);
This overload should be made available through trpc.useContext().setQueryData
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:21 (20 by maintainers)
Top Results From Across the Web
useContext - tRPC
useContext is a hook that gives you access to helpers that let you manage the cached data of the queries you execute via...
Read more >feat(trpc/next): allow passing complete QueryClient instead of ...
Describe the feature you'd like to request When using createTRPCNext, we can pass in a queryClientConfig in the config-callback, ...
Read more >Hooks API Reference - React
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. This page...
Read more >Build a full stack app with create-t3-app - DEV Community
Go to OAuth2/General and add all of callback URLs to Redirects . ... We can use the useSession() hook to get the session...
Read more >I am trying to use callback in hook but can not get latest ...
import React, { useCallback, useContext, useEffect } from 'react'; ... .on function should be updated as needed useEffect(() => { window.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve just updated the debouncer yet another time, as it turns out that the
onError
method of mutations discarded due to debouncing ran after theonMutate
callback of newer mutations. The wrong scheduling behavior messed up optimistic updates, so I came up with this:I’m not sure if React Query’s event handling can be invoked forcefully without relying upon a tiny event emitter from
nanoevents
. I just came across thenotifyManager.flush
method, but not sure if that’s applicable here.Nice, you know some nice typescript tricks, would love to see you apply them on some contributions to tRPC 😻