Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

How to implement Lexical to HTML Converter on the server?

default discord avatar
iokllast year
3

When going through the documentation at

https://payloadcms.com/docs/rich-text/lexical

. There is a line saying: "The lexicalHTML() function creates a new field that automatically converts the referenced lexical richText field into HTML through an afterRead hook."



I'm not sure how to interpret the statement. Does it mean


1. I need to implement a serialization mechanism in

afterRead

.


2. Or, Payload generates the content automatically.



Currently, what I see is this in the API call

nameOfYourRichTextField_html: ""

, meaning no HTML is generated. Am I missing something?

  • default discord avatar
    fanki1995last year

    You can use it in your collection as a field. You don't have to write a hook for it.


    But I guess you can't use it in a group, array or collapsible.

  • discord user avatar
    alessiogr
    last year
    through an afterRead hook.

    That just means that behind-the-back, this lexicalHTML feature uses an afterRead hook. It's added automatically, so no action required from your side!



    Only thing you have to do is to make sure that the first argument in the lexicalHTML function matches the field name



    Might not work if the richtext field is in a group/array yet, that's true. Will have to look into that

  • default discord avatar
    iokllast year

    Yes, my rich text is in a group. When I have time, I will play around with the implementation and open a GH issue if needed. In the meantime, I use the front end serializer as it has been working well since Slate.



    The issue for this was opened on GitHub, so I will close this thread:

    https://github.com/payloadcms/payload/issues/4034

    .

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team..