Comments (6)
Hey @ahmetskilinc, this is because you are attempting to import a server component into a client component, breaking the rules of React Server Components. The ListView
component performs server-side logic, including the use of the fs
module as your error indicates. Your MediaGrid
component, however, is marked with the use client
directive. Once you are past the client boundary, you cannot use server-only paradigms. You have two options you can take here:
- Write your component as a server component, so you can render the List View as needed. You can still interleave client components as needed.
- The pattern that Payload follows for cases like this is to pre-render those components on the server, and simply return them from client components. To do this, get the pre-rendered List View from the
useComponentMap
hook, and simply return it from your client component:This option is only valid within the Admin Panel, i.e. in a Custom Component. To use the'use client' import { useComponentMap } from '@payloadcms/ui' export const MyComponent = () => { const { ListView } = useComponentMap() return ListView }
ListView
outside the Admin Panel, you will need to import it into a server component and render it on the server (option 1).
from payload.
@jacobsfletch Gettin this now - Property 'ListView' does not exist on type 'IComponentMapContext'.
from payload.
@ahmetskilinc ok must be because you are attempting to use this hook outside the admin panel. I will add a disclaimer to my comment above indicating how this is not possible. For cases like this, you will need to use option 1: import and render the ListView
within a Server Component.
from payload.
@jacobsfletch The hook works in the same file to get getComponentMap
.
Doesn't this count as rendering it in the AdminPanel?
from payload.
Ah ok, looking now at the types and it appears to be called List
instead of ListView
, same with Edit
.
from payload.
This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.
from payload.
Related Issues (20)
- Plugin cloud storage upload file even when record is invalid
- Searching for number id: Unhandled Runtime Error (Error: invalid input syntax for type integer: "NaN") HOT 3
- Demo had no user -> Created one HOT 3
- Re: error on forgot-password route HOT 3
- Version publishing and draft permission weirdness HOT 4
- user is undefined after first user creation HOT 2
- Join field doesn't work for relationships that are nested within a tab field HOT 3
- Virtual fields do not have a list table name HOT 2
- Migration unable to run (Postgresql) HOT 3
- plugin-sentry: build fails with the Payload v2.28.0
- Write conflict error when deleting a document in afterChange hook HOT 4
- Unable to save content with umlauts in localized fields within a Global configuration HOT 3
- FieldLabel has incorrect props HOT 1
- Bug in @payloadcms/richtext-slate when upgrading to Payload 2.28.0 related to faceless-ui/modal
- Lexical custom block in new document (beta 108 regression) HOT 7
- Autosave makes it impossible to create new (localized) documents HOT 2
- create-payload-app creates project with duplicate graphql versions HOT 1
- delete operation doesn't return deleted id HOT 2
- Join Field: Incorrect Parent Relationship Assignment When Adding a New Document
- Row Field > alignment issue HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from payload.