From 505eb92b3b9cb9b0e37dd127db7105406fdc3f01 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Wed, 24 Aug 2022 10:15:35 +0200 Subject: [PATCH] add example for additional nodes in plugin (#2879) * add example for additional nodes in plugin * fix typo in plugin documentation --- .../docs/react/create_plugin.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/lexical-website-new/docs/react/create_plugin.md b/packages/lexical-website-new/docs/react/create_plugin.md index fa6f19d14bd..033a7e2d13d 100644 --- a/packages/lexical-website-new/docs/react/create_plugin.md +++ b/packages/lexical-website-new/docs/react/create_plugin.md @@ -14,6 +14,21 @@ Lexical's React plugin interface is simple - just create a React component and a ``` +If the Plugin introduces new nodes, they have to be registered in `initialConfig.nodes`: + +```js +const initialConfig = { + namespace: "MyEditor", + nodes: [MyLexicalNode], +}; +``` + +```jsx + + + +``` + LexicalComposer provides access to the underlying LexicalEditor instance via React Context: ```jsx @@ -35,7 +50,7 @@ export default function TwitterPlugin(): JSX.Element | null { useEffect(() => { if (!editor.hasNodes([TweetNode])) { - throw new Error('TwitterPlugin: TweetNode not registered on editor'); + throw new Error('TwitterPlugin: TweetNode not registered on editor (initialConfig.nodes)'); } return editor.registerCommand(