You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: adds code examples for how to fully implement textStateFeature (#16053)
Adds a "Rendering on the frontend" section under `TextStateFeature` with
clear examples:
- a shared config file
- how to reference that shared config when setting up TextStateFeature
in your field
- custom text JSX converter
alt="Example usage in light and dark mode for TextStateFeature with defaultColors and some custom styles"
480
480
/>
481
+
482
+
#### Rendering on the frontend
483
+
484
+
When Lexical serializes a text node that has state applied, the state is stored under a `"$"` key in the node object. To apply the styles when rendering rich text on your frontend, you need a custom `text` JSX converter that reads from this key and maps the values back to your CSS config.
485
+
486
+
**Step 1 — Share your state config**
487
+
488
+
Extract your `TextStateFeature` state into a file with no package imports so it can be safely imported in both server and client contexts:
When using [`RichText` from `@payloadcms/richtext-lexical/react`](/docs/rich-text/lexical#rendering-lexical-content-in-react), override the default `text` converter to read the `"$"` key and apply the corresponding CSS as inline styles:
The key insight is that `textStateConfig` is the single source of truth — it is passed directly to `TextStateFeature` in your field config and also imported by your frontend converter to resolve the CSS values at render time.
0 commit comments