How to avoid duplicate code in getServerSideProps?
Hey guys, sort of off-topic but lets say I have multiple components with getServerSideProps like this:
Is there a way I can avoid having to duplicate the portion:
every single time I want to check for a session?
7 Replies
Make a function
I'm fairly new with NextJS I figured I could have a sort of hook I could call. However my understanding is that you can't use hooks in getServerSideProps?
Nah. You can just make a function that takes in whatever and passed back whatever. Doesnt seem like you are using hooks in your code
Perhaps my understanding on what a hook is, is wrong. I just setup a function to verify the user and it worked 🙂
new function
now components can be called like this:
Nice 👍🏼
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Nice! Thank you again!