♻️ Improve query invalidation (#659)

This commit is contained in:
Luke Vella 2023-04-08 12:43:54 +01:00 committed by GitHub
parent 0ad5abb590
commit 5b6d8424af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 26 deletions

View file

@ -25,23 +25,19 @@ interface CommentForm {
const Discussion: React.FunctionComponent = () => {
const { dayjs } = useDayjs();
const queryClient = trpc.useContext();
const { t } = useTranslation("app");
const { poll, admin } = usePoll();
const pollId = poll.id;
const { data: comments } = trpc.polls.comments.list.useQuery(
{ pollId },
{
refetchInterval: 10000, // refetch every 10 seconds
trpc: {},
},
);
const { data: comments } = trpc.polls.comments.list.useQuery({ pollId });
const posthog = usePostHog();
const queryClient = trpc.useContext();
const addComment = trpc.polls.comments.add.useMutation({
onSuccess: () => {
queryClient.polls.comments.invalidate();
posthog?.capture("created comment");
},
});