#Fetching data from server component

5 messages · Page 1 of 1 (latest)

mighty night
#

My scenario is like I'm trying to list out online users in a page /online. Where the /online is server component(non 'use client'). External API endpoint is used to get online users using Axios. I was only getting the users active at the time of initial page load and the list was not updating even if I hit refresh page several times. Then I added export const revalidate = 60; in the server component, and all works fine.

I would like to know what had actually happened. An answer or any links would be helpful.

I was not completely aware of the reason. All I knew was the GET in the API route caches data by default. In my case also any caching happening?

regal dragonBOT
#

🔎 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)

amber raven
# mighty night My scenario is like I'm trying to list out online users in a page `/online`. Whe...

you are right. Return values of a GET route handler when using the response object are cached by default.
-> this could be one reason

Another reason could be, that the browser cached the whole page (by default 30 seconds) and after this time a new request was made to the server.
-> this could be also a reason

Keep in mind, that it's not recommended to use Axios anymore: https://www.adios-axios.com/

When you just want to update the page with the live data of online users, you can do this by leveraging a clientside fetching library. This will update the content of the page whenever it's needed

mighty night
#

Thanks for making it clear @amber raven !

amber raven
#

Happy to help