How can I useQuery when I click a button

I have this privateProcedure on the backend. I want to call it when I hit a button in my frontend:
checkDate: protectedProcedure
.input(z.object({ date: z.date() }))
.query(({ input, ctx }) => {
return {
message: 'hello world ' + input.date.toISOString(),
};
}),
checkDate: protectedProcedure
.input(z.object({ date: z.date() }))
.query(({ input, ctx }) => {
return {
message: 'hello world ' + input.date.toISOString(),
};
}),
How do I do that? I am btw gonna query a database for that date, and return something. I just simplified it for this example
6 Replies
barry
barry2y ago
mutation not query
sommeeeR
sommeeeROP2y ago
i thought mutation was for when you needed to change something? all i want to do is fetch something if it contains the date i pass in
barry
barry2y ago
semantics really doesnt matter what you use either for
sommeeeR
sommeeeROP2y ago
alright which should i use then?
barry
barry2y ago
mutation is the easy choice here, just works
sommeeeR
sommeeeROP2y ago
ok ill go for that then

Did you find this page helpful?