Question about hooks.

const Home: NextPage = () => {
const { data } = api.companyemployees.getCriticalContracts.useQuery(7);

const handleSnooze = (contractId: number) => {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const response = api.contracts.snoozeContract.useMutation({ contractId });
// Handle success response
console.log("Snooze successful:", response);
} catch (error) {
// Handle error
console.error("Failed to snooze:", error);
}
};
const Home: NextPage = () => {
const { data } = api.companyemployees.getCriticalContracts.useQuery(7);

const handleSnooze = (contractId: number) => {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const response = api.contracts.snoozeContract.useMutation({ contractId });
// Handle success response
console.log("Snooze successful:", response);
} catch (error) {
// Handle error
console.error("Failed to snooze:", error);
}
};
` Is it impossible to run handleSnooze like this on the frontend? If so, can somebody give me some pointers, please?
5 Replies
Neto
Neto2y ago
you should not create hooks conditionally
jps
jps2y ago
Don’t you have to do response.mutate({ contractId })
Neto
Neto2y ago
const Home: NextPage = () => {
const { data } = api.companyemployees.getCriticalContracts.useQuery(7);
const { mutate, mutateAsync error, isLoading } = api.contracts.snoozeContract.useMutation();

const handleSnooze = async (contractId: number) => {
// mutate{ contractId });
// await mutateAsync({ contractId })
};
const Home: NextPage = () => {
const { data } = api.companyemployees.getCriticalContracts.useQuery(7);
const { mutate, mutateAsync error, isLoading } = api.contracts.snoozeContract.useMutation();

const handleSnooze = async (contractId: number) => {
// mutate{ contractId });
// await mutateAsync({ contractId })
};
jps
jps2y ago
Yea Create it then just call the mutate part
VIIKKK
VIIKKKOP2y ago
Oh ok i see Thanks a lot!
Want results from more Discord servers?
Add your server