Next.js Discord

Discord Forum

Send data in original response or make API calls?

Unanswered
Chum salmon posted this in #help-forum
Open in Discord
Chum salmonOP
Hi again,

I have products I want to sell on my page, which are represented via a <Product /> tag. I was debating whether or not it was a better idea to prop drill JSON data for the component into all of the products on the initial page load, or if it would make more sense to just pass in a product ID which can be queried from my client API once the initial page has loaded?

JSON Example:
<Product jsonData={productJson[0]} /> - Product component will not query database, since the JSON data was sent on the initial response.

API Example:
<Product productID=0 /> - Product component will query client API with product 0 and display it that way, so the page should load faster since there isn't any large data or processing to be done for the product. This is done for all components, so I believe multiple API calls.

I think I heard that NextJS will add placeholders while the page is loading and all the JS is running, but I'm not sure if it's for this use case or not.

Thanks!

1 Reply

Chum salmonOP
or I guess another alternative is to create another component, like <ProductSelection /> which accepts an array of product IDs, and it makes 1 client API call, which then passes JSON into each child <Product /> component?