Open
Description
Hey all, awesome project! This is allowing me to easily switch away from swr
over to using tanstack/query
.
One thing I miss however is the ability to easily update the query cache.
With swr, each instance has a mutate
function that includes the curried key, so I can easily pass it the new value.
With the current iteration of this library, the refetch
function that is returned from useQuery
takes no parameters.
In order for me to update the underlying cache, I have to do something like this:
const queryclient = useQueryClient();
const { mutateAsync } = useMutation(createMyValue);
async function onSubmit(values: MyFormValues): Promise<void> {
const resp = await mutateAsync(...values...);
queryclient.setQueryData(
createConnectQueryKey(geyMyValue, {
id: resp.myvalue.id,
}),
new GetMyValueResponse({
myvalue: resp.myvalue,
})
);
}
I'd love it if there were an easier way to trigger a cache update for a useQuery
value that didn't involve so much boilerplate.
Metadata
Assignees
Labels
No labels