You are currently viewing documentation for Payload 4 beta. Some documentation may be incomplete or change before release.
Rendering On Demand
Lexical in Payload is a React Server Component (RSC). Historically that created three headaches: 1. You couldn't render the editor directly from the client. 2. Features like blocks, tables and link drawers require the server to know the shape of nested sub-fields at render time. If you tried to render on demand, the server didn't know those schemas. 3. The rich text field is designed to live inside a Form. For simple use cases, setting up a full form just to manage editor state was cumbersome.
To simplify rendering richtext on demand, <RenderLexical />, that renders a Lexical editor while still covering the full feature set. On mount, it calls a server action to render the editor on the server using the new render-field server function. That server render gives Lexical everything it needs (including nested field schemas) and returns a ready-to-hydrate editor.
RenderLexical and the underlying render-field server function are experimental and may change in minor releases.
Inside an existing Form
If you have an existing Form and want to render a richtext field within it, you can use the RenderLexical component like this:
schemaPath tells the server which richText field to render. This gives the server the exact nested field schemas (blocks, relationship drawers, upload fields, tables, etc.).
Format:
collection.<collectionSlug>.<fieldPath>
global.<globalSlug>.<fieldPath>
Example (top level): collection.posts.richText
Example (nested in a group/tab): collection.posts.content.richText
Tip: If your target editor lives deep in arrays/blocks and you're unsure of the exact path, you can define a hidden top-level richText purely as a "render anchor":
1
{
2
name:'onDemandAnchor',
3
type:'richText',
4
admin:{hidden:true}
5
}
Then use schemaPath="collection.posts.onDemandAnchor"