TanStackT
TanStack6mo ago
8 replies
endless-jade

Server functions or which feature??

Hi all, I'm looking for some advice about which feature from tanstack start do I need for this use case.
1) I have a 1 page app. The main file I have is $.tsx this file catches everything and fetch the content from our headless CMS, for example: /about-us in the browser will trigger an API call for the slug about-us.
2) The cms API response is basically an array of objects where each object has a
type
key to know which ReactJS component render, for example columns, text, banner, and so on.
3) One of these "cms components" is a FAQs section, around 80% of my pages have this component and I need to run some custom logic to enable/disable this query that's why my reactjs component uses
useQuery
instead of
useSuspenseQuery
, because not all pages need this component and even if they have it, not all of them will run the query.
 
I was thinking to add the logic + api call on my loader, but I don't want to overload my loaders. is this ok?
Even if I add it to my loaders, it needs to be conditionally, and if I do that, the component will need to use
useQuery
and not
useSuspenseQuery
.

What options do I have?

I'm thinking to play around with server functions.
My goal is to send all of the HTML from the server to avoid roundtrips and make it SEO friendly.
IMG_5884.jpg
IMG_5885.png
IMG_5886.png
IMG_5887.png
Was this page helpful?