Skip to content

[bug]: Cannot pass custom components in server-side components in NextJS #47

Open
@wzrdx

Description

@wzrdx

What version of @strapi/blocks-react-renderer are you using?

"@strapi/blocks-react-renderer": "^1.0.1",
"react": "^18.3.1"

What's Wrong?

I am trying to use the BlocksRenderer inside a server component in my NextJS app. I want to pass a custom component for links.

<BlocksRenderer
    content={article.attributes.Content}
    blocks={{
        link: ({ children, url }) => (
            <Link href={url} target="_blank">
                {children}
            </Link>
        ),
    }}
/>

I get the following error:

⨯ Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it.
  {link: function link}
         ^^^^^^^^^^^^^
    at stringify (<anonymous>)

To Reproduce

Create a NextJS app using the /app router and create a new page (page.tsx).

Render the BlocksRendered inside of it and try to pass a custom component.

Expected Behaviour

The page should render without errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions