Unhandled Runtime Error

Top of the code
const doTraduzioneLatino = (text: string) => {
if (textAreaLatinoRef.current?.value) {
return api.user.doTraduzioneLatino.useQuery({ text, email: email ?? '' })
}
}
const doTraduzioneLatino = (text: string) => {
if (textAreaLatinoRef.current?.value) {
return api.user.doTraduzioneLatino.useQuery({ text, email: email ?? '' })
}
}
Other part of the code
const handleClickLatino = () => {
const text = textAreaLatinoRef?.current?.value;
if (text) {
const notify = () => toast.success("Traduzione in corso...");
notify();
console.log(doTraduzioneLatino(text));
} else {
const notify = () => toast.error("Inserisci un testo!");
notify();
}
}
const handleClickLatino = () => {
const text = textAreaLatinoRef?.current?.value;
if (text) {
const notify = () => toast.success("Traduzione in corso...");
notify();
console.log(doTraduzioneLatino(text));
} else {
const notify = () => toast.error("Inserisci un testo!");
notify();
}
}
How can I fix that?
5 Replies
dopeinc
dopeinc14mo ago
You cannot call react hook inside if statement or loops it need to be at the top of component : react.dev look at hooks : https://react.dev/learn#using-hooks
Quick Start – React
The library for web and native user interfaces
dopeinc
dopeinc14mo ago
Disabling/Pausing Queries | TanStack Query Docs
If you ever want to disable a query from automatically running, you can use the enabled = false option. When enabled is false:
dopeinc
dopeinc14mo ago
Also you should probably use an i18n lib for traduction Instead of using trpc depending on your need
yourny🤫🧏🏼
But how can I do this if I have to pass arguments such as text within a textarea? I mean by putting it at the top
dopeinc
dopeinc14mo ago
useState two way binding inputs enabled opts on query