T3 App Router Service Layer
I am migrating from the pages to app router manually on my app that was generated by create-t3-app. In my existing app, I had a service layer that was accessed via a data hook that maintained the state of an entity (
Is there anything I can change to make a common service layer able to be reused by a data hook (or any client component for that matter) AND directly from server components? Or is there a new approach that aligns better with server components in general? Apologies for the likely elementary question, very new to server components and learning as I go. Thanks!
useRecipe() that would call the service layer implementation for loading, updating, deleting a recipe where the components would pull that state in). I’ve converted the service layer to use the new ~/trpc/server file (as opposed to the new ~/trpc/react file) so these new functions can be used by not only the data hook, but called directly from server components. This allows reusability in my service layer for conversions, etc. It seems to make sense to me to reuse these funcs rather than call trpc directly from server components to align with reusability and encapsulation “best practices” (please correct me if I’m wrong). Calling these funcs works great from my server components, but when I try to use my data hook on client components that now have the service layer that use the "use server"; instance of trpc, I am getting this error:Is there anything I can change to make a common service layer able to be reused by a data hook (or any client component for that matter) AND directly from server components? Or is there a new approach that aligns better with server components in general? Apologies for the likely elementary question, very new to server components and learning as I go. Thanks!
