Best way to access things from a client module inside a server component #63291
Replies: 2 comments 8 replies
-
|
I am a bit confused here, why can't you import
In the screenshot above from, https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#using-context-providers, they import a Carousel component from a |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.



Uh oh!
There was an error while loading. Please reload this page.
-
Let's say I have a shared client component that is rendered in a load of places across my app, PostItem.tsx for example.
Ideally I'd like to specify the types for this PostItem in the same file, and because im using prisma it's possible to infer this type based on the selected fields:
this means that any server component/page that is going to render that item could import this select fields object and I know that whenever the post item fields change the selected fields from the DB will change automatically and all types will work correctly - similar to defining a fragment in graphql and using that fragment in the top level query.
However this is not possible as I cant import anything from a "use client" file in a server component, any ideas? currently having to make a file next to the PostItem called like postItemFields.ts, that handles just the select + type, so at least its semi-location, but not ideal really.
Beta Was this translation helpful? Give feedback.
All reactions