Next.js Discord

Discord Forum

Load on the server with refreshInterval: 1000

Unanswered
Devon Rex posted this in #help-forum
Open in Discord
Devon RexOP
Need to understand the load on the server while using refreshInterval: 1000
This is my fetcher function:
const fetcher = async ({ url, forumId }: { url: string; forumId: string }) => {
  const res = await axios.get(`${url}`, {
    params: { forumId: forumId },
  });
  return res.data;
};

And this is my useSWR:
const { data, error, isLoading } = useSWR(
    { url: `/api/forums/${forumId}`, forumId },
    fetcher,
    { refreshInterval: 1000 }
  );


I want to actually refetch the data only when there is a new thread posted, not necessarily every second (1000 ms).
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
    e.preventDefault();
    setIsCreateThread(false);
    try {
      const response = await axios.post(`/api/forums/${forumId}`, {
        title,
        content,
        forumId,
      });
      console.log(response.data);
    } catch (error) {
      console.log(error);
    }
  };


How can I do that?

1 Reply

Devon RexOP
Should I use mutate?