How to share/organize common logic for ssr and client side code #17516
Unanswered
karanpvyas
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a use case where I need to make authenticated calls to my backend to serve data.
This means -
i) I'd need to run some logic for building my request
ii) Attach the necessary auth headers which I'd get in a cookie from the browser - before I make a call within
getServerSideProps
iii) Be able to do/use the same code for making calls (e.g. pagination on scroll) when inside client/browser now.
P.S. There are several calls - bootup/data-fetch etc which need to be made when
gettingServerSideProps
.I am wondering what's the best way to do so when
SSR
ingAlso P.S. -> Uptil now when I didn't do any SSR, I had several global variables/configs available in my React context on the browser side, using which I could "make" my request's payload and then do the n/w calls.
Now within getServerSideProps -> I no more have React Context of any sort, and need to pass on my configs/global variables all the way down to all function calls :(
Any help/insight would be appreciated, thanks you!
Beta Was this translation helpful? Give feedback.
All reactions