Giter Club home page Giter Club logo

Comments (6)

jacobsfletch avatar jacobsfletch commented on September 26, 2024

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:

  1. Write your component as a server component, so you can render the List View as needed. You can still interleave client components as needed.
  2. 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:
    'use client'
    import { useComponentMap } from '@payloadcms/ui'
    
    export const MyComponent = () => {
      const { ListView } = useComponentMap()
      return ListView
    }
    This option is only valid within the Admin Panel, i.e. in a Custom Component. To use the 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.

ahmetskilinc avatar ahmetskilinc commented on September 26, 2024

@jacobsfletch Gettin this now - Property 'ListView' does not exist on type 'IComponentMapContext'.

from payload.

jacobsfletch avatar jacobsfletch commented on September 26, 2024

@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.

ahmetskilinc avatar ahmetskilinc commented on September 26, 2024

@jacobsfletch The hook works in the same file to get getComponentMap.
Doesn't this count as rendering it in the AdminPanel?

from payload.

jacobsfletch avatar jacobsfletch commented on September 26, 2024

Ah ok, looking now at the types and it appears to be called List instead of ListView, same with Edit.

from payload.

github-actions avatar github-actions commented on September 26, 2024

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

from payload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.