danmrkw
danmrkw
TTCTheo's Typesafe Cult
Created by danmrkw on 3/29/2023 in #questions
setData doesn't update state
I want to replace query invalidation with an update of the query cache to make my application react quicker. My understanding is that I use the setData method to update the query cache on success of the mutation. I've done so here:
const optionStateMut = api.option.updateOptionState.useMutation({
onSuccess: (data) => {
client.form.getForm.setData({ formId: currentFormId }, (oldData) => {
const newData = oldData;
const fieldIdx = newData!.fields.findIndex(
(element) => element.id === currentFieldId
);
newData!.fields[fieldIdx]!.options = data;
console.log("newData: ", newData);
return newData;
});
// void client.form.getForm.invalidate();
},
onError: () => {
toast.error("technical error updating options");
},
});
const optionStateMut = api.option.updateOptionState.useMutation({
onSuccess: (data) => {
client.form.getForm.setData({ formId: currentFormId }, (oldData) => {
const newData = oldData;
const fieldIdx = newData!.fields.findIndex(
(element) => element.id === currentFieldId
);
newData!.fields[fieldIdx]!.options = data;
console.log("newData: ", newData);
return newData;
});
// void client.form.getForm.invalidate();
},
onError: () => {
toast.error("technical error updating options");
},
});
The console logged newData looks exactly like I want it to. However the website doesn't update. It still shows oldData. What am I doing wrong?
3 replies
TTCTheo's Typesafe Cult
Created by danmrkw on 3/22/2023 in #questions
create csv on the backend and server for download
I have a table called pollResults. It contains data that my users want to download into a csv file. What is the best way to generate that file on the backend (using t3 stack) and then serve it as a download on the client? ideally without getting anything like S3 involved.
13 replies
TTCTheo's Typesafe Cult
Created by danmrkw on 2/20/2023 in #questions
type of a TRPC mutation
What is the type of a TRPC mutation if I want to pass it into a component
export default function MyComponent({ myMutation} : {myMutation: ???} {
// mutating things...
}
export default function MyComponent({ myMutation} : {myMutation: ???} {
// mutating things...
}
8 replies
TTCTheo's Typesafe Cult
Created by danmrkw on 2/3/2023 in #questions
Is tRPC restful
Is an API created with tRPC restful?
2 replies
TTCTheo's Typesafe Cult
Created by danmrkw on 1/29/2023 in #questions
trpc query only once parameter is not null
New in T3 stack so forgive me if this is a noob question: I am trying to run a trpc query only if a user is logged in. The user id is part of the query parameter. const { data: sessionData } = useSession(); const cart = api.cart.getCart.useQuery({ userId: sessionData?.user?.id }); Normally I would just add sessionData to the query key but there is no option for that here right? Or is there?
10 replies