Next.js Discord

Discord Forum

Where do you put server actions that are scoped to a component rather than a page?

Answered
Florian posted this in #help-forum
Open in Discord
I use this PostInput component in different places. I'm unsure where to put the corresponding server action 🤔 Inside the components folder feels wrong.
Answered by B33fb0n3
then I would put the action where my component is
View full answer

9 Replies

@Florian I use this `PostInput` component in different places. I'm unsure where to put the corresponding server action 🤔 Inside the components folder feels wrong.
I keep mine inside the matching folder to know, that all actions about this path (also components) are inside this actions file
@B33fb0n3 I keep mine inside the matching folder to know, that all actions about this path (also components) are inside this actions file
I do that too if the actions belong to a page. But in my example, they belong to a reusable component that's not tied to a specific page. Hence my confusion.
Answer
@B33fb0n3 then I would put the action where my component is
So in a subfolder in the components folder? LIke this?
@B33fb0n3 yes
thank you
happy to help. Please mark solution
I'm still interested in other opinions