Next.js Discord

Discord Forum

fetch or pass as props

Answered
Briard posted this in #help-forum
Open in Discord
BriardOP
should i pass the single blog information as props from home page? or fetch it again fetchSinglePostById()
Answered by LuisLl
Server-to-server you can call fetchSinglePostById() again with no problem, as long as this function is being cached to avoid making a request twice. This way each component only worries about the data they need, without depending on who their parent is.

Server-to-client you should prefer fetching on the server and passing data down as props.
View full answer

2 Replies

Server-to-server you can call fetchSinglePostById() again with no problem, as long as this function is being cached to avoid making a request twice. This way each component only worries about the data they need, without depending on who their parent is.

Server-to-client you should prefer fetching on the server and passing data down as props.
Answer
Spectacled bear
If you have the data on the home page and it is the same piece of data you're gonna show, you can pass it as a prop. It's a common practice and saves you few lines of code until unless data is different or can be changed.