Ideas For A Centralized useServerAction() Hook In Next.js 14 - Seeking Input #62720
Unanswered
duhoshina
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Ideas For A Centralized useServerAction() Hook In Next.js 14 - Seeking Input
Hello, friends!
I am currently neck-deep in a React project using Next.js 14 and have found the need for calling 'use server' frequently in a wide range of files throughout my application. I've been mulling over this and figured there might be a more efficient approach - creating a custom hook, perhaps.
I've tentatively decided to name this hook 'useServerAction()'. This hook will take in a function as an argument and then make certain that this function is executed on the server. To boil it down, I'm hoping to devise a 'handler' sort of a structure that accepts a function and executes the 'use server' command within the hook's body, centralizing all server instructions.
Here's a scuffed draft of what I intend:
Before diving headfirst into this, I felt like bouncing the idea off the community to evaluate if it makes sense. Are there any specific caveats, performance, or say, security issues I should be wary of?
Any and all feedback, questions or suggestions are most welcome.
Much appreciated and thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions