higgsboz
higgsboz
TTCTheo's Typesafe Cult
Created by kdiffin on 5/6/2023 in #questions
running a query only if a boolean is true
^ Correct
12 replies
TTCTheo's Typesafe Cult
Created by Tom on 5/3/2023 in #questions
Fire trpc useQuery only when a callback is called
You should be able to accomplish this using 2 things. 1. Set enabled: false in the query options 2. Call tournamentQuery.refetch in your useEffect when your condition is true
const trpcUtils = trpc.useContext();
const {data, refetch} = trpc.tournaments.getTournamentInternal.useQuery(
{ tournamentID: id ?? "", version: 0 },
{ enabled: false, keepPreviousData: true }
);

useEffect(() => {
/* prevents errors when id is empty due to SSR */
if (!id) return;

const unsubscribe = registerTournamentChangedListener(id, (v) => {
refetch()
});
return () => {
unsubscribe();
};
});
const trpcUtils = trpc.useContext();
const {data, refetch} = trpc.tournaments.getTournamentInternal.useQuery(
{ tournamentID: id ?? "", version: 0 },
{ enabled: false, keepPreviousData: true }
);

useEffect(() => {
/* prevents errors when id is empty due to SSR */
if (!id) return;

const unsubscribe = registerTournamentChangedListener(id, (v) => {
refetch()
});
return () => {
unsubscribe();
};
});
6 replies
TTCTheo's Typesafe Cult
Created by Radu on 5/8/2023 in #questions
Aborting a T3 mutation
3 replies
TTCTheo's Typesafe Cult
Created by kdiffin on 5/6/2023 in #questions
running a query only if a boolean is true
To expand on the above, enabled: false just means that useQuery will not fire on mount. You can still call refetch() and it'll pull you're data
12 replies