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
Neto17mo ago
you should not create hooks conditionally
jps
jps17mo ago
Don’t you have to do response.mutate({ contractId })
Neto
Neto17mo 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
jps17mo ago
Yea Create it then just call the mutate part
VIIKKK
VIIKKK17mo ago
Oh ok i see Thanks a lot!
Want results from more Discord servers?
Add your server