Best Practices for Using Server Actions as Fetcher in SWR #2972
Unanswered
AlexandreCrevel-Ose
asked this question in
Q&A
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.
-
Hello everyone,
I'm currently working on a Next.js 14 POC. I've got a django backend and I don't want to expose it to the client.
My idea is to use server actions to handle every API calls.
I've got a custom function to fetch data from server side components.
For client components, I want to use SWR with a custom fetcher function defined on top level of my app (with a SWRProvider).
Here is a simplified version of my code :
My SWR Configuration :
Discussion Points
Do you see errors, bad practices, any comment on this code?
Performance: Are there any performance concerns with this approach, particularly regarding latency and server load?
Caching and Revalidation: How should I best handle caching and revalidation both on the server-side and client-side components (using SWR)?
Error Handling: Is my current error handling strategy effective, or are there better patterns to follow?
Best Practices: Are there any best practices or recommendations for using server actions as a fetcher in SWR that I should be aware of?
I appreciate any insights or advice from the community. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions