#Can a server-side RSC update itself at a specific internal?

35 messages · Page 1 of 1 (latest)

echo condor
#

I'm creating a digital clock component and currently using "use client" and "useEffect"

 useEffect(() => {
    const timer = setInterval(() => {
      setDate(new Date());
    }, clockConfig.refreshInterval);
    return () => {
      clearInterval(timer);
    };
  }, []);

Is there a way to do this with a server-side component?

steady horizonBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
fervent basin
echo condor
#

How would I handle that with setting a refresh interval?

fervent basin
#

Except instead of setDate() you router.refresh()

echo condor
#

Hmm...next/router doesn't have router.refresh()

#

oh from next/navigation

#

so weird these lib names

echo condor
#

So, I'm still somewhat confused. useEffect already takes care of updating the browser. Why do I need to router.refresh() at all?

#

Is this just so I don't need to use a state variable for the date?

fervent basin
#

If you don’t need to rerun the server components to get latest data from them you don’t need to do it

#

I don’t understand what you mean by “useEffect already takes care of updating the browser”

echo condor
#

I guess ultimately my question is: is there anything wrong with the code I posted in the OP? Does router.refresh() and useTransition() do something "better" than what is already tehre?

fervent basin
echo condor
#

My apologies, as I really am a novice react/nextjs user but...it does update/work. The interval is setup to run every 500 ms to set the date to the current date, then the date is displaying in the HTML.

#

So the interval timer is called inside the useEffect to refresh the time every 500ms

fervent basin
echo condor
#

Correct!

#

You said I couldn't do it in a server component.

#

So I'm fine with that (that was my original question)

fervent basin
#

Because you cannot run client side logic in server components

echo condor
#

But then you suggested using things like useTransition and router.refresh() which is where I got confused.

fervent basin
#

So what exactly is your question?

fervent basin
echo condor
#

You said this:

with pure RSC, no. but you can use a client component with a similar logic and call router.refresh() in a startTransition call to refresh the page

So I thought you were suggesting using a client component in a different/better way than what I was doing already.

fervent basin
#

Ok, ignore every single thing that I said then. And tell me what you are really asking about

#

What do you want to do

#

We are 29 messages in and I don’t know what your question is

echo condor
#

I'm creating a digital clock that displays the current time in the browser. I posted my code above as a way to do it using client components. My original question was whether there was a server-side component way of doing it.

#

just because I want to use server-side as much as possible until you can't

fervent basin
echo condor
#

Cool, thanks. Sorry for all the time spent on it. I appreciate your help!