Hi author, i have a proplem relate about fecth data in nextjs,, can you suggest me.
I building a blog like dev.to.I have router for post like /post/[slug].tsx.
Im using getStacticProps for all post and every the post user can leave a comment like this comment.
When user add comment, if refresh the post then will see comment not show because the post had get from cache before.
At second refresh it get updated.
getServerSideProps can fix it but i think it not good for this case.All post should cache to fast load.
And can you help me or suggest some solution.
Thank so much.
If you want the comments to be updated each time the page loads you need to use getServerSideProps. If you are wanting fast pages use getStaticProps and re-fetch the data once the page has loaded - check out swr.vercel.app/ which is a React hook that can help with this.
Tks bro, i still using swr to fecth data from api.But i think post list should use getStaticProps togenerated at build time and will be reused on each request.
Hi author, i have a proplem relate about fecth data in nextjs,, can you suggest me.
I building a blog like dev.to.I have router for post like /post/[slug].tsx.
Im using getStacticProps for all post and every the post user can leave a comment like this comment.
When user add comment, if refresh the post then will see comment not show because the post had get from cache before.
At second refresh it get updated.
getServerSideProps can fix it but i think it not good for this case.All post should cache to fast load.
And can you help me or suggest some solution.
Thank so much.
If you want the comments to be updated each time the page loads you need to use
getServerSideProps
. If you are wanting fast pages usegetStaticProps
and re-fetch the data once the page has loaded - check out swr.vercel.app/ which is a React hook that can help with this.Tks bro, i still using swr to fecth data from api.But i think post list should use getStaticProps togenerated at build time and will be reused on each request.
Yeah that sounds sensible.