mongoosenext.jsserverbackendaction

Nextjs actions, how to make a mongoose call from action?


and should it be done? or should the actual mongoose call of find needs to be inside route.ts file as an api and inside the action of nextjs i should make a http fetch call to this api?

my problem is mostly:

Thanks


Solution

  • The purpose of actions in nextjs are to seperate concerns between the view to the data manipulation like http fetch from the server side of nextjs - meaning that when a component that initially rendered in the backend can perform a server side http request and afterwards perform the same http request on the client side with the same actions - this is why it's important to have a separation of concerns to allow the isomoprhic nature of the code execute smoothly!

    Here are some best practice for action in nextjs:

    The goal of actions in nextjs are:

    Good luck!