r/reactjs • u/Dazzling_Chipmunk_24 • May 24 '26
Best practice for fetching "recently used" forms— server-side (Next.js) or client-side API call?
I have two lists in my app: "All Forms" (fetched server-side in Next.js and passed to React) and "Recently Used Forms." When the component first loads I need to fetch the recently used list, but I also need to re-fetch it every time a user clicks a form from the All Forms sections, since clicking updates the list on the backend. So since I have to re-call the API on clicks anyway, I'm wondering if it even makes sense to fetch the initial data server-side, or if I should just handle everything client-side with a useEffect on mount and re-trigger it on each click. Which approach is better?
4
u/yksvaan May 24 '26
I don't quite understand, what's the point of loading the recently used list evey time from server instead just adding the latest entry locally? Sounds like pointless extra work
1
u/AwayVermicelli3946 May 25 '26
tbh i usually just handle highly interactive user lists entirely client side. server rendering is great for initial data, but for a recents list that changes on every click, tying it to the server just complicates your state management.
if you are already using Next.js, bringing in SWR or React Query makes this trivial. you can fetch on mount and then just optimistically update the local cache when they click a form.
it saves a round trip to the backend on every click and makes the app feel way snappier. fwiw i spent a lot of time fighting useEffect chains before just leaning on a cache library for this exact pattern.
-4
u/Ceryyse May 24 '26 edited Jun 01 '26
Don't use useEffects, the react docs explicitly state you may not need it.
If you're hell bent on using Next.js, make use of server actions.
If you're willing to listen, switch to Vite + React and use Tanstack Query for fetching & caching.
Edit: idk why I'm being downvoted, I'm right.
0
u/[deleted] May 24 '26
[deleted] — view deleted comment
-3
u/[deleted] May 24 '26
[removed] — view removed comment