DEV Community

Shubham Kumar
Shubham Kumar

Posted on

Is this the correct way to use useSWR with getServerSideProps?

This is the code sandbox example of how I'm using SWR with getServerSideProps: https://codesandbox.io/s/useswr-with-getserversideprops-nextjs-9u1gp?file=/containers/PostContainer/index.js

github repo link
What I want to achieve is on the post/[post] page the meta tags will be dynamic coming from the backend & will be users specific that's why I'm using getServerSideProps instead of getStaticProps, the above code is working fine but when I see the terminal on clicking a post it's calling the API 3 times & when I again click the same post API is being called 2 times is this normal behaviour?

Top comments (0)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay