Server action not being triggered
Unanswered
not-milo.tsx posted this in #help-forum
I just started fiddling with server actions. I'm trying to implement a view counter and trigger a server action that increments the counter in my db every time a page is loaded.
I have no errors, the action works as expected but it doesn't get triggered... I'm using
action.ts
ViewCount.tsx
Am I doing something wrong?
I have no errors, the action works as expected but it doesn't get triggered... I'm using
useTransition to call the action.action.ts
"use server";
import { supabase } from "~/lib/supabase";
export const incrementViewCount = async () => {
// ...working increment logic...
};ViewCount.tsx
// ...imports...
export const ViewCount = ({ message }: { message: string }) => {
let [isPending, startTransition] = useTransition();
const { data, isLoading } = useSWR<{ count: number; error?: string }>(
"/api/viewCount",
fetcher
);
useEffect(() => {
startTransition(() => incrementViewCount());
}, []);
// ...component structure...
}Am I doing something wrong?