Next.js Discord

Discord Forum

server action next in client side

Unanswered
Gharial posted this in #help-forum
Open in Discord
Avatar
GharialOP
hi my problem is that i can't receive my data from my server side and it return error serverError everytime,

this is my client side :
useEffect(() => {
      const fetchAndSetStats = async () => {
        const {data, serverError} = await getLinkStatistics({ slug: "lol", continent: "All" });
        console.log("qzdqzd ==", data, serverError);
        
        if (data) {
          setStats({
            uniqueVisitorsCurrent: data.uniqueVisitorsCurrent ?? 50,
            totalVisitsCurrent: data.totalVisitsCurrent ?? 0,
            uniqueVisitorPercentageChange: data.uniqueVisitorPercentageChange ?? 0,
            totalVisitPercentageChange: data.totalVisitPercentageChange ?? 0,
            uniqueVisitorTrend: data.uniqueVisitorTrend ?? '',
            totalVisitTrend: data.totalVisitTrend ?? '',
          });
        }
      };
    
      fetchAndSetStats();
    }, []);


and this is my server side :
const GetStatsSchema = z.object({
  slug: z.string(),
  continent: z.string().optional()
});
export const getLinkStatistics = authenticatedAction(
  GetStatsSchema,
  async (props, { userId }) => {
// things 
return {
      uniqueVisitorsCurrent,
      totalVisitsCurrent,
      uniqueVisitorPercentageChange,
      totalVisitPercentageChange,
      uniqueVisitorTrend,
      totalVisitTrend,
    };
  }
);

0 Replies